2012-06-13 79 views
1

我正在創建一個應用程序快捷方式。它工作正常。但我無法刪除這個快捷方式。如何刪除我的應用程序快捷鍵。在我的主屏幕中包含很多應用程序快捷方式。如何刪除..
如果可能請發送有關如何刪除應用程序快捷方式的信息。否則,如果它不可能發送原因。請回復你的回答,評論對我很有價值。謝謝。
我的示例代碼是在這裏...如何創建和刪除應用程序快捷方式到主屏幕?

Button btnShortcut = (Button) findViewById(R.id.btnCreateShortcut); 
    btnShortcut.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View arg0) 
     { 
      Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); 
      shortcutintent.putExtra("duplicate", false); 
      shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); 
      Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher); 
      shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); 
      shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , MyActivity.class)); 
      sendBroadcast(shortcutintent); 
     } 
    }); 

我的Android的Manifest.xml代碼是在這裏...

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

這是一個無證和不支持的技術。這不適用於所有主屏幕,因此不適用於所有設備。 – CommonsWare

+0

謝謝。但是我的模擬器主屏幕包含多個相同的快捷方式。我能做什麼?如何刪除這個。 – Bala

回答

1

在這裏你去

private void deleteShortCut(Context context) { 

    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); 
    shortcutIntent.setClassName("com.example.androidapp", "SampleIntent"); 
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    shortcutIntent.putExtra("someParameter", "HelloWorld"); 

    Intent removeIntent = new Intent(); 
    removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
    removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "ShortcutName"); 
    removeIntent.putExtra("duplicate", false); 

    removeIntent 
      .setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");  
    context.sendBroadcast(removeIntent); 
} 
+0

對不起。我檢查了這個代碼。我的應用程序快捷方式沒有刪除其他解決方案。 – Bala

+0

就我的研究而言 - no:/ – Guy

相關問題