5,598,233 Members 47,308 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Delete shortcut duplicate

Tip us?
 
gato06
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 14
Join Date: Nov 2012
Default [Q] Delete shortcut duplicate

I need create a shortcut when the app is installed and the code works fine
the problem is that when I open the app view another shortcut
example if I open 20 times the app
this created 20 times shortcut


@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
borrarIcono();
agregarIcono();
}

private void agregarIcono(){

Intent shortcutIntents = new Intent(getApplicationContext(), Main.class);
shortcutIntents.addFlags(Intent.FLAG_ACTIVITY_NEW_ TASK);
shortcutIntents.addFlags(Intent.FLAG_ACTIVITY_CLEA R_TOP);

Intent addIntent = new Intent();

addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntents);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Whatsapp Imagenes");
addIntent.putExtra("DUPLICATE", false);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESO URCE, Intent.ShortcutIconResource.fromContext(getApplica tionContext(), R.drawable.icono));
addIntent.setAction("com.android.launcher.action.I NSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);


}


private void borrarIcono(){


Intent shortcutIntent = new Intent(getApplicationContext(), Main.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_T ASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR _TOP);
shortcutIntent.putExtra("someParameter", "Whatsapp Imagenes");

Intent removeIntent = new Intent();
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT , shortcutIntent);
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Whatsapp Imagenes");
removeIntent.setAction("com.android.launcher.actio n.UNINSTALL_SHORTCUT");

getApplicationContext().sendBroadcast(removeIntent );
}
 
Critical Detox
Old
#2  
Critical Detox's Avatar
Senior Member
Thanks Meter 99
Posts: 230
Join Date: Oct 2010
Location: Buffalo
Quote:
Originally Posted by gato06 View Post
I need create a shortcut when the app is installed and the code works fine
the problem is that when I open the app view another shortcut
example if I open 20 times the app
this created 20 times shortcut


@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
borrarIcono();
agregarIcono();
}

private void agregarIcono(){

Intent shortcutIntents = new Intent(getApplicationContext(), Main.class);
shortcutIntents.addFlags(Intent.FLAG_ACTIVITY_NEW_ TASK);
shortcutIntents.addFlags(Intent.FLAG_ACTIVITY_CLEA R_TOP);

Intent addIntent = new Intent();

addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntents);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Whatsapp Imagenes");
addIntent.putExtra("DUPLICATE", false);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESO URCE, Intent.ShortcutIconResource.fromContext(getApplica tionContext(), R.drawable.icono));
addIntent.setAction("com.android.launcher.action.I NSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);


}


private void borrarIcono(){


Intent shortcutIntent = new Intent(getApplicationContext(), Main.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_T ASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR _TOP);
shortcutIntent.putExtra("someParameter", "Whatsapp Imagenes");

Intent removeIntent = new Intent();
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT , shortcutIntent);
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Whatsapp Imagenes");
removeIntent.setAction("com.android.launcher.actio n.UNINSTALL_SHORTCUT");

getApplicationContext().sendBroadcast(removeIntent );
}
Is the phone doing this by its self or did you make it that way?
Tags
android, develers, newbie
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes