0

Can I read the label text from the application shortcut that invoked my Android program?

I can read the application name:

getString(R.string.app_name)

but that's not what i want. It needs to be the custom label text that is assigned to the shortcut.

I plan to have multiple shortcuts with different labels. The label will influence some behaviour of my program.

leticia
  • 2,390
  • 5
  • 30
  • 41

2 Answers2

0

No, the launching shortcut's label is not passed to you in any manner.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
0

You don't necessarily need to know the name or text of the shortcut you made, instead you can use that shortcut to "pass arguments" to the activity via an intent. Your shortcut will be a regular Activity, it will just pass an argument to the main Activity of your application using an Intent.

Intent i = new Intent(this, SomeActivity.class);
i.putExtra("some_tag", true);
startActivity(i);

And in the Activity to be launched,

@Override
protected void onNewIntent(Intent in) {
    super.onNewIntent(in);

    if(in.hasExtra("some_tag") && in.getExtra("some_tag") == true) {
        //Do Something Special
    }
}

Note that you need launchMode set to singleTop to use onNewIntent() as noted here: http://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)

More information can be found here:

http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/11444-add-shortcuts-your-android-application.html

David Freitag
  • 2,252
  • 2
  • 16
  • 18