如何在WebView应用程序中打开深层链接 [英] How to open Deep Links in webview application

查看:81
本文介绍了如何在WebView应用程序中打开深层链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了我的Webview应用程序,并且在onCreate方法中将我的主URL加载到了Webview.然后我实现了像这样的深层链接:

i have created my webview application and i loaded my main url in onCreate method to webview. then i implemented the deep links like this:

我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ariagp.myapplication">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">


        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>


            <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="https" android:host="mysitename.com" />
            </intent-filter>
        </activity>
    </application>

</manifest>

现在,当点击深层链接时,该应用程序将在Webview主页上打开.但是我想打开与深层链接相关的页面.

Now when the deep links get clicked, the app will open on the webview homepage. But I want to make the page related to the deep link open.

打开应用程序本身后,打开主页.解决办法是什么?

And when the app itself opens, make the home page open. what is the solution?

推荐答案

启动活动后,在 onNewIntent(Intent intent)方法中,从 intent 获取数据(应该是点击的网址-深度链接),其类型为 uri ,然后将该网址加载到您已实现的网络视图中.

When the activity is launched, in the onNewIntent(Intent intent) method, get data from intent (it is supposed to be the url clicked - deep link) which has the type uri, and then load that url in the web view that you've implemented.

类似下面的代码:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Uri data = intent.getData();
        
    webView.loadUrl(data.toString());
}

这篇关于如何在WebView应用程序中打开深层链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆