2010-10-02 12 views
0

Dans mon application, j'ai un ListView lorsque l'utilisateur clique sur un élément qu'une action est effectuée. Maintenant, je veux faire un menu contextuel pour l'élément de liste avec la possibilité d'ajouter cette action à l'écran d'accueil comme un raccourci. Quelqu'un pourrait-il m'offrir un lien ou un indice sur la façon de le faire?Raccourci sur l'écran d'accueil pour une action dans mon application

Répondre

0
private void createShortcut(Command command){ 
    Intent shortcutIntent = new Intent(this, FormActivity.class); 
    // As binary because OS does not know type Command 
    command.putToIntentAsXml(shortcutIntent); 
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

    Intent intent = new Intent(); 
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, command.getTitle()); 
    Parcelable iconResource = Intent 
     .ShortcutIconResource 
     .fromContext(this, R.drawable.ic_launcher); 
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); 
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 

    sendBroadcast(intent); 
} 
Questions connexes