简体   繁体   中英

Android Intent - Extras not found on first load from url

I'm trying to load my application from a webpage via deep linking.

I'm using window.location to call the intent url when a webpage is hit.

The app opens fine using: window.location("intent://open/#Intent;scheme=testapp;package=gb.testapp.testapp;S.id=3026;end"); however, the id that I'm trying to pass in only seems to appear if the URL is loaded for a second time...

My Intent in AndoridManifest.xml is:

<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="testapp"  android:host="open" android:path="/" />
 </intent-filter>

I'm calling the following code in my MainActivity.java

public void onNewIntent(Intent intent) {

        super.onNewIntent(intent);

         Bundle extras = getIntent().getExtras();
         System.out.println("URLLOAD -  " + intent.getDataString());
         if (extras != null){
             String sid = extras.getString("id");

             if (sid!=null)
             {
                 System.out.println("URLLOAD - FOUND PARAMS");
             }


         }else{
             System.out.println("URLLOAD -  NO PARAMS");
         }
}

This results in: First time opening url after app install:

System.out﹕ URLLOAD -  testApp://open/
System.out﹕ URLLOAD -  NO PARAMS

Opening the URL again

I/System.out﹕ URLLOAD -  testApp://open/?id=3026
I/System.out﹕ URLLOAD - FOUND PARAMS

Has anyone come across a similar issue or can see an issue with my code?

Thanks, Simon

My guess would be that the first time you launch your acitivty (app) the onCreate() method is being called instead of onNewIntent(). For all subsequent calls your activity is "updated" via the onNewIntent method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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