package com.example.launcherdemo;
import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class ShortcutActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT)) {
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "shortcut");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, MainActivity.class));
setResult(RESULT_OK, intent);
finish();
}
}
}
清单文件
<activity android:name=".ShortcutActivity" >
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
</intent-filter>
</activity>