[英]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.