<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > android 創(chuàng)建 刪除桌面快捷方式

          android 創(chuàng)建 刪除桌面快捷方式

          作者: 時(shí)間:2016-10-08 來(lái)源:網(wǎng)絡(luò) 收藏

          創(chuàng)建

          本文引用地址:http://www.ex-cimer.com/article/201610/305647.htm

          /**

          為程序創(chuàng)建桌面快捷方式

          */

          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); //不允許重復(fù)創(chuàng)建

          //指定當(dāng)前的Activity為快捷方式啟動(dòng)的對(duì)象: 如 com.everest.video.VideoPlayer

          //注意: ComponentName的第二個(gè)參數(shù)必須加上點(diǎn)號(hào)(.),否則快捷方式無(wú)法啟動(dòng)相應(yīng)程序

          ComponentName comp = new ComponentName(this.getPackageName(), “.“+this.getLocalClassName());

          shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));

          //快捷方式的圖標(biāo)

          ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);

          shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

          sendBroadcast(shortcut);

          }/**

          為程序創(chuàng)建桌面快捷方式

          */

          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); //不允許重復(fù)創(chuàng)建

          //指定當(dāng)前的Activity為快捷方式啟動(dòng)的對(duì)象: 如 com.everest.video.VideoPlayer

          //注意: ComponentName的第二個(gè)參數(shù)必須加上點(diǎn)號(hào)(.),否則快捷方式無(wú)法啟動(dòng)相應(yīng)程序

          ComponentName comp = new ComponentName(this.getPackageName(), “.“+this.getLocalClassName());

          shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));

          //快捷方式的圖標(biāo)

          ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);

          shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

          sendBroadcast(shortcut);

          }

          2, 刪除

          /**

          刪除程序的快捷方式

          */

          private void delShortcut(){

          Intent shortcut = new Intent(“com.android.launcher.action.UNINSTALL_SHORTCUT”);

          //快捷方式的名稱

          shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));

          //指定當(dāng)前的Activity為快捷方式啟動(dòng)的對(duì)象: 如 com.everest.video.VideoPlayer

          //注意: ComponentName的第二個(gè)參數(shù)必須是完整的類名(包名+類名),否則無(wú)法刪除快捷方式

          String appClass = this.getPackageName() + “.” +this.getLocalClassName();

          ComponentName comp = new ComponentName(this.getPackageName(), appClass);

          shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));

          sendBroadcast(shortcut);

          }/**

          刪除程序的快捷方式

          */

          private void delShortcut(){

          Intent shortcut = new Intent(“com.android.launcher.action.UNINSTALL_SHORTCUT”);

          //快捷方式的名稱

          shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));

          //指定當(dāng)前的Activity為快捷方式啟動(dòng)的對(duì)象: 如 com.everest.video.VideoPlayer

          //注意: ComponentName的第二個(gè)參數(shù)必須是完整的類名(包名+類名),否則無(wú)法刪除快捷方式

          String appClass = this.getPackageName() + “.” +this.getLocalClassName();

          ComponentName comp = new ComponentName(this.getPackageName(), appClass);

          shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));

          sendBroadcast(shortcut);

          }

          3, 聲明權(quán)限

          在AndroidManifest.xml 文件中聲明 創(chuàng)建和刪除快捷方式時(shí)聲明權(quán)限

          Java代碼



          關(guān)鍵詞:

          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();