您的位置:首页 > 其它

设置桌面快捷方式

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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: