簡體   English   中英

Android Intent-從url首次加載時未找到其他功能

[英]Android Intent - Extras not found on first load from url

我正在嘗試通過深層鏈接從網頁加載我的應用程序。

當網頁被點擊時,我正在使用window.location調用意圖URL。

該應用程序可以使用以下方法正常打開: window.location("intent://open/#Intent;scheme=testapp;package=gb.testapp.testapp;S.id=3026;end"); 但是,我嘗試傳遞的ID僅在第二次加載URL時才會出現...

我在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>

我在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");
         }
}

結果是:在應用安裝后首次打開網址:

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

再次打開URL

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

是否有人遇到類似問題或我的代碼有問題?

謝謝西蒙

我的猜測是,第一次啟動活動(應用程序)時,將調用onCreate()方法而不是onNewIntent()。 對於所有后續調用,您的活動將通過onNewIntent方法“更新”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM