lundi 23 février 2015

Create progammatically an home screen shortcut to a non main activity


I want to create a shortcut on the phone's home screen. I want that clicking a button on the main activity puts on a shortcut on the home screen to another activity (so not the main) and at the same time transmitting some parameters (strings).


If for example the main activity is of class A and the phone's home screen shortcut target activity is of class B, how must I process ? A code snippet would just help me fine !


PS : I tried this code, but it only works with «launcher.setClassName(this, "com.mycorp.mypck.A")», not with «launcher.setClassName(this, "com.mycorp.mypck.B")» :



Intent launcher = new Intent(Intent.ACTION_MAIN);
launcher.setClassName(this, "com.mycorp.mypck.B");
launcher.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent shortcut = new Intent();
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "BlaBla");
shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(shortcut);


NB : Maybe I just lack a manifest entry...





Aucun commentaire:

Enregistrer un commentaire