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上工作?
感謝提前:)