默认Shortcut操作
缺省情况下,安装的APP应用程序(Launcher属性)的图标将出现在“抽屉面板”中。 jsdgk可以通过长按并拖动图标将其拖动到桌面上来添加快捷方式。
长按桌面图标时,“抽屉面板”中的小箭头会变成垃圾桶图标,拖动图标会将其删除。
对Shortcut列表的添加/删除操作
在默认桌面空间中按键,将显示选择对话框。 选择Shortcut,找到并添加要添加的APP应用程序快捷方式。
首先,将应用的选项添加到Shortcut列表中,然后直接访问代码。
//*
添加到Shortcut选项(在默认桌面上长按调用) ) ) ) ) )。
*
*此外,manifest还必须包含在活动中
* action=' Android.intent.action.create _ shortcut '中的intent-filter
*/
隐私保护
//创建默认Intent
Intent shortcut=new Intent (;
//快捷方式的名称
shortcut.put extra (intent.extra _ shortcut _ name,getstring(r.string.app_name ) );
//不允许重复创建
shortcut.putextra('duplicate ',false );
//指定当前活动作为快捷方式启动的对象:例如com.everest.video.VideoPlayer
: ComponentName的第二个参数必须带有点(.)。 否则,快捷方式无法启动相应的程序
stringappclass=this.get package name ('.' this.getlocalclassname );
componentnamecomp=newcomponentname (this.get package name )、appClass );
shortcut.put extra (intent.extra _ shortcut _ intent,newintent(intent.action_main ).setcomponent ) comp );
//以下方法与上面的效果相同,只是另一种构建形式
//intentrespondintent=new intent (this,this.getClass ();
//shortcut.put extra (intent.extra _ shortcut _ intent,respondIntent );
//快捷方式图标
shortcuticonresourceiconres=intent.shortcuticonresource.from context (this,R.drawable.icon );
shortcut.put extra (intent.extra _ shortcut _ icon _ resource,iconRes );
//发送到消息队列
setresult(result_ok,shortcut );
}
应用重新安装/卸载时将自动删除
对Shortcut的直接添加/删除操作(按代码)
要点:
为Intent指定action=' com.Android.launcher.install _ shortcut '
在定义为Intent.EXTRA_SHORTCUT_INENT的Intent中设置与安装时匹配的操作(
将权限: com.Android.launcher.permission.install _ shortcut添加到AndroidManifest.xml
//*
*为程序创建桌面快捷方式
*
在manifest中还必须设置以下权限:
*
*/
私密void添加短路
intent shortcut=new intent (com.Android.launcher.action.install _ shortcut );
//快捷方式的名称
shortcut.put extra (intent.extra _ shortcut _ name,getstring(r.string.app_name ) );
//不允许重复创建
shortcut.putextra('duplicate ',false );
//指定当前活动作为快捷方式启动的对象:例如com.everest.video.VideoPlayer
//在此,必须为Intent设置任意操作。 (但是,安装和卸载时参数必须匹配。 )
string action=' com.Android.action.test ';
intentrespondintent=new intent (this,this.getClass ();
respondintent.setaction(action;
shortcut.put extra (intent.extra _ shortcut _ intent,respondIntent );
//以下方法与上面的效果相同,只是另一种构建形式
: ComponentName的第二个参数必须带有点(.)。 否则,快捷方式无法启动相应的程序
//stringappclass=this.get package name ('.' this.getlocalclassname );
//componentnamecomp=newcomponentname (this.get package name )、appClass );
//shortcut.put extra (intent.extra _ shortcut _ intent,newintent(action ).setcomponent ) comp );
//快捷方式图标
shortcuticonresourceiconres=intent.shortcuticonresource.from context (this,R.drawable.icon );
shortcut.put extra (intent.extra _ shortcut _ icon _ resource,iconRes );
发送广播(shortcut;
}