Reputation: 8488
In my app I am creating a home screen shortcut for my app using following code:
HomeScreenShortCut.setAction(Intent.ACTION_MAIN);
HomeScreenShortCut.putExtra("duplicate", false);
//shortcutIntent is added with addIntent
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, HomeScreenShortCut);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Handbook Manual");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
This is working fine and shortcut is getting created. But, rather than hardcoding the name of shortcut, I want to give it from string file like this:
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, R.string.app_name);
But after making this change shortcut is not getting created which is really wierd. I need this as my app supports multiple languages and even the name of app is based on language. I am testing on Samsung Galaxy S3.
Please help..
Upvotes: 2
Views: 118
Reputation: 8170
Here it is!
Have you tried using getString(R.string.app_name)
? Remember that R.string.app_name
is an integer, not a string.
Upvotes: 1
Reputation: 642
Hi try to used this coding in the app
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));
instead of this
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, R.string.app_name);
i hope this help u
Upvotes: 1