Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void setDeskShortCut() {
- SharedPreferences sp = getSharedPreferences("SP", MODE_PRIVATE);
- boolean installedshortcut = sp.getBoolean("installedshortcut", false);
- if (installedshortcut) {
- return;
- }
- // 创建一个快捷方式的意图
- Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
- intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, // 快捷方式的名称
- getString(R.string.app_name));
- intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
- BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); // 快捷方式的图标
- // 设置点击这个快捷方式,打开哪个activity
- Intent openMS = new Intent("com.hy.test.activities.home");
- openMS.addCategory("android.intent.category.DEFAULT");
- intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, openMS); // 快捷方式的打开界面
- sendBroadcast(intent); // 发送一个广播
- Editor editor = sp.edit();
- editor.putBoolean("installedshortcut", true);
- editor.commit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement