how do i handle this string to open my app

倖福魔咒の 提交于 2019-12-02 12:23:14

问题


i get this string in a browser redirect

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

how do i work with it ?

found in : 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/08/26/url-schemes-for-ios-and-android-1/

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

package=com.myapp;scheme=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 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
        }
    }

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 ?



来源:https://stackoverflow.com/questions/20545373/how-do-i-handle-this-string-to-open-my-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!