两种快捷创建方式:
* 1,长按桌面选择或者小部件拖动
* 2,在本app创建
快捷方式和Launcher的有关。可以看看Launcher里对快捷方式的支持
1,增加图标到长按快捷方式列表,点击快捷方式要启动的activity
eg:
在activity的intent-filter增加action:CREATE_SHORTCUT
点击快捷方式后的伪activiy,来完成动画,像金山的快捷方式
2,上面activity的java的操作:在桌面创建快捷方式
* 1,长按桌面选择或者小部件拖动
* 2,在本app创建
快捷方式和Launcher的有关。可以看看Launcher里对快捷方式的支持
1,增加图标到长按快捷方式列表,点击快捷方式要启动的activity
eg:
<activity
android:name="com.example.shortcutdemo.LauncherShortcuts"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >(为了启动activity时看不到界面,只运行创建快捷方式的方法)
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
</intent-filter>
</activity>
在activity的intent-filter增加action:CREATE_SHORTCUT
点击快捷方式后的伪activiy,来完成动画,像金山的快捷方式
<activity
android:name=".activities.ActShortcutOneKey"
android:taskAffinity="com.hiapk.kbatterydoctor.shortonkey" <!-- 这个属性很重要,为了防止home键后,打开此activity时,同时打开和他一个task的activity-->
android:excludeFromRecents="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
2,上面activity的java的操作:在桌面创建快捷方式
public class LauncherShortcuts extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
createShortCut();
} else {
setResult(RESULT_CANCELED);
}
finish();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void createShortCut() {
// 点击快捷方式前往的intent
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
// shortcutIntent.setClassName(this, this.getClass().getName());
shortcutIntent.setClass(this, OneKeyActivity.class);//-------OneKeyActivity.java是下面的伪动画界面。像金山电池的快速清理快捷方式。
// 封装到新的intent,给Launcher
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getString(R.string.app_name));
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this,
R.drawable.ic_launcher);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
setResult(RESULT_OK, intent);
//这里如果是本app要创建的话,sendBroadcast(intent);
}
}