Android深层链接会打开应用两次。

huangapple go评论63阅读模式
英文:

Android Deeplink opens application twice

问题

我使用了 WebView 创建应用,并实现了如下的深度链接:

<?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>

但在打开链接之前会询问我是否要用我的应用程序打开链接,问题是
在手机任务管理器中会打开两个应用程序(应用程序不会在之前运行的应用程序中打开):

Android深层链接会打开应用两次。

有什么解决办法吗?

英文:

i used webview to create app and implemented deep linking like this:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    package=&quot;com.ariagp.myapplication&quot;&gt;

    &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;

    &lt;application
        android:allowBackup=&quot;true&quot;
        android:icon=&quot;@mipmap/ic_launcher&quot;
        android:label=&quot;@string/app_name&quot;
        android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
        android:supportsRtl=&quot;true&quot;
        android:theme=&quot;@style/AppTheme&quot;&gt;


        &lt;activity android:name=&quot;.MainActivity&quot;&gt;
            &lt;intent-filter&gt;
                &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &lt;/intent-filter&gt;


            &lt;intent-filter&gt;
                &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;
                &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
                &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt;
                &lt;data android:scheme=&quot;https&quot; android:host=&quot;mysitename.com&quot; /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;

&lt;/manifest&gt;

it will asking my for open with my application before open the links, but the problem is:
two applications will open in the phone task manager (the application does not open in the previous application which is running):

Android深层链接会打开应用两次。

what is the solution?

答案1

得分: 8

AndroidManifest.xml 中的声明的活动中添加 android:launchMode="singleTask"

然后,在您的活动中,您应该重写 onNewIntent() 方法,您将在其中获得参数。

英文:

Add android:launchMode=&quot;singleTask&quot; in declared activity in AndroidManifest.xml.

And then, in your activity, you should override onNewIntent() method and you will get arguments there.

答案2

得分: -1

好的,这里实际上没有问题。
这只是深层链接的工作原理。如果在特定的应用中打开一个深层链接,该链接将在原始深层链接所在的窗口中打开您的应用。
您的应用程序在某种程度上将具有两个实例。

您可以打开您的网络浏览器应用,然后点击分享,选择任何弹出的应用。它们都会在网络浏览应用程序窗口中打开。所以不用担心。我之前也遇到过同样的问题,后来我意识到这只是事物运行方式。

某些应用程序经过验证,如果它们实现了可浏览性,就可以打开其他应用程序。

英文:

Ok, so you don't actually have a problem here.
This is just how deep links work. If you open one in a certain app, the deep link will open your app but in the same window the deep link was originally in.
Your app will have two instances in a way.

You could go to you web brower app and click share and any app that pops up. They all open in the web browsing app window. So there is nothing to worry about. I had the same problem myself before I realised that it is just how things work.

Some apps are just verified to open other apps if they implement the browsability.

huangapple
  • 本文由 发表于 2020年10月12日 05:24:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/64309152.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定