设置桌面快捷方式
2010-06-24 14:37
309 查看
如何在程序中设置桌面快捷方式(home screen shortcut):
/**
*创建桌面图标(Home Screen Shortcut)
*
* @param context the context
* @param clz 快捷方式启动的Activity
*/
public static void makeShortcut(Context context,Class<?> clz) {
//设置快捷方式的目标Activity
//该Activity一般具有如下的设置:
// <intent-filter>
// <action android:name="android.intent.action.MAIN" />
// <category android:name="android.intent.category.LAUNCHER" />
// </intent-filter>
Intent shortcutIntent = new Intent(context,clz);
// shortcutIntent.setClassName(packageName, name);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getResources().getString(R.string.app_name));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon) );
intent.setAction(Intent.ACTION_CREATE_SHORTCUT);
context.sendBroadcast(intent);
}
/**
*创建桌面图标(Home Screen Shortcut)
*
* @param context the context
* @param clz 快捷方式启动的Activity
*/
public static void makeShortcut(Context context,Class<?> clz) {
//设置快捷方式的目标Activity
//该Activity一般具有如下的设置:
// <intent-filter>
// <action android:name="android.intent.action.MAIN" />
// <category android:name="android.intent.category.LAUNCHER" />
// </intent-filter>
Intent shortcutIntent = new Intent(context,clz);
// shortcutIntent.setClassName(packageName, name);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getResources().getString(R.string.app_name));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon) );
intent.setAction(Intent.ACTION_CREATE_SHORTCUT);
context.sendBroadcast(intent);
}
相关文章推荐
- Ubuntu 16.04 pycharm设置桌面快捷启动方式
- Fedora17设置终端快捷键 和 桌面快捷方式
- Eclipse桌面快捷方式如何设置打开指定的workspace
- 开机默认设置一个widge在指定的屏幕上和自动在桌面上创建一个应用的快捷方式的方法
- 长按桌面进入小部件,选择“设置快捷方式”里任意一个添加到桌面,在设置中将语音设置为英语,添加的快捷方式依然是中文
- 怎么设置桌面关机的快捷方式
- ubuntu16.04设置应用程序桌面快捷方式(QQ为例)
- 在Ubuntu 12.04 桌面上设置启动器(快捷方式)
- Ubuntu14.04 x64系统设置Qt5.8桌面快捷方式
- Android桌面快捷方式的设置(一)
- 如何给桌面的快捷方式设置快捷键
- Ubuntu14.10中为Android Studio设置桌面快捷方式
- 在Ubuntu 桌面上设置启动器(快捷方式)
- 在Ubuntu 12.04 桌面上设置启动器(快捷方式)过程讲解:
- Ubuntu16.04 下设置桌面快捷方式
- Android桌面快捷方式的设置(一)
- Linux中为Matlab配置中文字体,以及设置桌面启动快捷方式
- [Fedora 20] 设置Terminal快捷键 + 设置桌面快捷方式 + Terminal透明解决方案
- Ubuntu11.10设置桌面启动器(桌面快捷方式)
- [转]Fedora17设置终端快捷键 和 桌面快捷方式