现在的位置: 首页 > 综合 > 正文

android 创建快捷方式

2018年01月29日 ⁄ 综合 ⁄ 共 555字 ⁄ 字号 评论关闭

部分代码:

private void shortCut(){
		
		Intent intent = new Intent();
		intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
		intent.putExtra("duplicate", false);
		intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "hello");//标题
		Intent.ShortcutIconResource sr = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);//自定义图标
		intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, sr);
		intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, this.getClass()));
		this.sendBroadcast(intent);
	}

权限配置:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
【上篇】
【下篇】

抱歉!评论已关闭.