I am trying to create an app which will create multiple shortcut of the same app with user input as the shortcut name. but every shortcut will do different specified things.For this I need to know the shortcut name.any possible way to fo that?
Asked
Active
Viewed 155 times
-1
-
Possible duplicate of [Add Shortcut for android application To home screen On button click](http://stackoverflow.com/questions/10343414/add-shortcut-for-android-application-to-home-screen-on-button-click) – Eren Utku Aug 21 '16 at 01:02
-
Hi @Ratul ! Did you find a way of doing this ? – Syeda Zunaira May 02 '17 at 06:05
1 Answers
0
First you need the INSTALL_SHORTCUT permission
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
You can use the code below and make changes
EditText UserInput = (EditText)findViewById(R.id.userinput_text);
final String UserString = UserInput.getText().toString();
//Gets user input^
public void createIcon(){
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
//So the shortcut doesn't get created multiple times
shortcutintent.putExtra("duplicate", false);
//UserString is the text from the user input to set the shortcut name
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(UserString));
//set the icon picture
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new
//Set the Activity that will be opened
Intent(getApplicationContext(), EnterActivity.class));
sendBroadcast(shortcutintent);
}
That will add a shortcut to the launcher and open a custom activity from your app. I'm not sure what you're really trying to do as it's unclear of what you're asking for.

Greg432
- 530
- 4
- 25