Android創建快捷方式圖標

cm54 9年前發布 | 751 次閱讀 Java Android

一個方法,在APP需要的時候調用該方法即可:

    public void createShortcutIconInHomeScreen() {

        Intent addIntent = new Intent();  
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent());  
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式名字");  

        // 不重復創建快捷方式圖標。  
        addIntent.putExtra("duplicate", false);  

        // R.drawable.app_logo 快捷方式的圖標icon。  
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,  
                Intent.ShortcutIconResource.fromContext(  
                        getApplicationContext(), R.drawable.app_logo));  
        addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");  
        getApplicationContext().sendBroadcast(addIntent);  
    }  </pre> 


添加權限:

    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>     

 本文由用戶 cm54 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!