本文實例講述了android編程實現為程序創建快捷方式的方法。分享給大家供大家參考,具體如下:
/*** 為程序創建桌面快捷方式*/private void addShortcut(){Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");//快捷方式的名稱shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));shortcut.putExtra("duplicate", false); //不允許重復創建//指定當前的Activity為快捷方式啟動的對象: 如//com.everest.video.VideoPlayer//注意: ComponentName的第二個參數必須加上點號(.),否則快捷方式無法啟動相應程序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);}
希望本文所述對大家Android程序設計有所幫助。
新聞熱點
疑難解答
圖片精選