1
创建一个独特的快捷键安装应用时行为有所我用下面的代码来创建一个快捷方式安装的应用程序时:不同的Android版本
在AndroidManifest.xml:
<!-- for creating a shortcut in the home screen -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
中的onCreate( )主要活动:
// an Intent to create a shortCut
Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
//repeat to create is forbidden
shortcutIntent.putExtra("duplicate", false);
//set the name of shortCut
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, this.getString(R.string.app_name));
//set icon
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
//set the application to lunch when you click the icon
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT
, new Intent(getApplicationContext() , MainActivity.class));
//sendBroadcast,done
sendBroadcast(shortcutIntent);
这些代码在安卓4.0.4,其产生在第一时间快捷方式,并发送举杯说的快捷方式已经EXI做工精细sts在第一次安装后。但在Android 4.2.2中,我可以通过单击后退键创建许多重复的快捷方式,然后再次输入应用程序。
有没有什么办法可以在两个版本的Android上工作?
感谢提前:)