从JS(网络浏览器)到android活动的方案调用不会使用url字符串中的方案数据来更新意图

问题描述 投票:0回答:1

我正在从浏览器启动应用程序,如果尚未加载/运行该应用程序,它将通过onCreate启动该应用程序并收集intent.data并执行正确的操作。如果该应用程序已经在运行,则从浏览器启动该应用程序将绕过onCreate并转到onResume,我“相信”这是预期的行为。但是与从浏览器启动相关联的intent.data为空。我希望将意图数据用方案url字符串中的新意图数据覆盖,以便我可以使用新参数在应用程序内重新启动Webview。当浏览器启动(即恢复)新数据时,是否可以通过某种方式将其推送到应用中?

//具有要传递给应用程序的参数的JS浏览器代码。

var r = Math.random();
window.open("myScheme://caca.com/?mode=driver" + "&ec=" + ec + "&uh=" + $("#userHandle").val() + "&at=0" + "&random=" + r);

// Xamarin

onResume(...) {

    ...

    try
    {

        // currentActivity.Intent.Data != null if app is not already running
        // is null if already running

        Android.Net.Uri data = currentActivity.Intent.Data;
        string scheme = data.Scheme;

        DebugToast("scheme " + scheme, ToastLength.Long);

        if (scheme == "myScheme")
        {
            // force the cookies so the web app will come up as we specify

            SetStorageValue("browserLaunched", "true");
            SetStorageValue("mode", data.GetQueryParameter("mode"));
            SetStorageValue("ec", data.GetQueryParameter("ec"));
            SetStorageValue("uh", data.GetQueryParameter("uh"));
            SetStorageValue("authToken", data.GetQueryParameter("at"));
            SetStorageValue("at", data.GetQueryParameter("at"));

            DebugToast("parms " + data.GetQueryParameter("mode") + " " +  data.GetQueryParameter("ec") + " " + data.GetQueryParameter("uh") + " " +  data.GetQueryParameter("at"), ToastLength.Long);

            // restart the web view with arguments above

            ...

        }
    }
    catch
    {
       ....
    }
}
android url android-activity browser url-scheme
1个回答
0
投票

荷马·辛普森D'哦!需要在活动中添加“ onNewIntent()”,以接收带有附加数据的“新”意图。

© www.soinside.com 2019 - 2024. All rights reserved.