如何阅读从调用我的Andr​​oid应用程序快捷方式的标签文本? [英] How do I read the label text from the shortcut that invoked my Android App?

查看:163
本文介绍了如何阅读从调用我的Andr​​oid应用程序快捷方式的标签文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从应用程序的快捷键的调用我的Andr​​oid程序?读取标签文本

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.

推荐答案

您不一定需要知道的名字或者你所做的快捷方式的文本,而不是您可以使用该快捷方式通过,以传递参数的活动意图。您的快捷方式将是一个常规性活动,它会使用一个Intent只是参数传递到应用程序的主要活动。

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
    }
}

请注意,您需要 launchMode 设置为 singleTop 使用 onNewIntent()为这里要注意:
<一href=\"http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29\"相对=nofollow称号=Android开发者活动Documentation\">http://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)

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:

<一个href=\"http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/11444-add-shortcuts-your-android-application.html\"相对=nofollow称号=添加快捷方式到你的Andr​​oid application\">http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/11444-add-shortcuts-your-android-application.html

这篇关于如何阅读从调用我的Andr​​oid应用程序快捷方式的标签文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆