简体   繁体   English

Android Intent-从url首次加载时未找到其他功能

[英]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. 当网页被点击时,我正在使用window.location调用意图URL。

The app opens fine using: window.location("intent://open/#Intent;scheme=testapp;package=gb.testapp.testapp;S.id=3026;end"); 该应用程序可以使用以下方法正常打开: 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... 但是,我尝试传递的ID仅在第二次加载URL时才会出现...

My Intent in AndoridManifest.xml is: 我在AndoridManifest.xml中的意图是:

<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 我在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 再次打开URL

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(). 我的猜测是,第一次启动活动(应用程序)时,将调用onCreate()方法而不是onNewIntent()。 For all subsequent calls your activity is "updated" via the onNewIntent method. 对于所有后续调用,您的活动将通过onNewIntent方法“更新”。

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

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