简体   繁体   English

如何从调用Android应用程序的快捷方式中读取标签文本?

[英]How do I read the label text from the shortcut that invoked my Android App?

Can I read the label text from the application shortcut that invoked my Android program? 我可以从调用我的Android程序的应用程序快捷方式中读取标签文本吗?

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. 标签将影响我的程序的某些行为。

不,启动快捷方式的标签不会以任何方式传递给您。

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. 您的快捷方式将是常规的Activity,它将使用Intent将参数传递给应用程序的主Activity。

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) 请注意,您需要将launchMode设置为singleTop才能使用onNewIntent() ,如此处所述: http : //developer.android.com/reference/android/app/Activity.html#onNewIntent onNewIntent()

More information can be found here: 更多信息可以在这里找到:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM