1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > android 4.2 桌面快捷方式 Android 添加桌面快捷方式操做

android 4.2 桌面快捷方式 Android 添加桌面快捷方式操做

时间:2023-02-01 15:11:45

相关推荐

android 4.2 桌面快捷方式 Android 添加桌面快捷方式操做

/** android

* 为程序建立桌面快捷方式 app

*/ ide

private void addShortcut(){ this

Intent shortcut = new Intent(“com.android.launcher.action.INSTALL_SHORTCUT”); rest

//快捷方式的名称 对象

shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); get

shortcut.putExtra(“duplicate”, false); //不容许重复建立 string

//指定当前的Activity为快捷方式启动的对象: 如 //com.everest.video.VideoPlayer it

//注意: ComponentName的第二个参数必须加上点号(.),不然快捷方式没法启动相应程序 io

ComponentName comp = new ComponentName(this.getPackageName(), “.”+this.getLocalClassName());

shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));

//快捷方式的图标

ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);

shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

sendBroadcast(shortcut);

}

/**

* 删除程序的快捷方式

*/

private void delShortcut(){

Intent shortcut = new Intent(“com.android.launcher.action.UNINSTALL_SHORTCUT”);

//快捷方式的名称

shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));

//指定当前的Activity为快捷方式启动的对象: 如 //com.everest.video.VideoPlayer

//注意: ComponentName的第二个参数必须是完整的类名(包名+类名),不然没法删除快捷方式

String appClass = this.getPackageName() + “.” +this.getLocalClassName();

ComponentName comp = new ComponentName(this.getPackageName(), appClass);

shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));

sendBroadcast(shortcut);

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。