如何处理这个字符串,打开我的应用程序我的、字符串、如何处理、应用程序

2023-09-07 23:04:18 作者:死党不一定要死

我得到这个字符串,在浏览器重定向

i get this string in a browser redirect

原意://查看ID = 123#意图;包= com.myapp;计划=的myapp; launchFlags = 268435456;结束;

intent://view?id=123#Intent;package=com.myapp;scheme=myapp;launchFlags=268435456;end;

我如何使用它?

在发现:的http:// fokkezb.nl/2013/09/20/url-schemes-for-ios-and-android-2/

推荐答案

您已经在同一篇文章的第1部分答案:

You have your answer in the part 1 of the same article :

http://fokkezb.nl / 2013/8月26日/ URL-计划换IOS和 - 机器人-1 /

您的活动必须有一个意图过滤器匹配给定的意图 在这里,您有:

Your activity must have an intent filter matching the given intent Here you have :

package=com.myapp;scheme=myapp

您的应用程序包必须的 com.myapp 的和URL方案的的myapp:// 的 所以,你必须声明你的活动这样的:

Your app package must be com.myapp and the url scheme is myapp:// So you must declare your activity like that :

<activity android:name=".MyActivity" >
     <intent-filter>
         <action android:name="android.intent.action.VIEW"/>
         <category android:name="android.intent.category.DEFAULT"/>
         <category android:name="android.intent.category.BROWSABLE"/>
         <data android:scheme="myapp" />
     </intent-filter>
 </activity>

那么你的活动将被自动机器人打开。

Then your activity will be automatically opened by android.

Optionnaly可以一起工作的URI从code接收到的,例如在onResume方法(为什么onResume - >,因为它总是叫onNewIntent后?):

Optionnaly you can work with the uri received from your code, for example in the onResume method (why onResume ? -> because it is always called after onNewIntent) :

    @Override
    protected void onResume() {
        super.onResume();

        Intent intent = getIntent();
        if (intent != null && intent.getData() != null) {
            Uri uri = intent.getData();
            // do whatever you want with the uri given
        }
    }

如果您的活动采用onNewIntent,我推荐使用setIntent使得code以上,就总是执行去年的意图:

If your activity uses onNewIntent, i recommend to use setIntent so that code above is always executed on last intent :

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
    }

这是否回答你的问题?

Does this answers your question ?