Deeplink on click opens intent chooser in android

橙三吉。 提交于 2019-12-12 06:31:50

问题


I have implemented deeplinking in one for my activities. But when the link is clicked, an Intent chooser opens asking whether to open from the app or from the browser. How to open from app directly?

Also, when the app is not installed, it does not take to playstore. It opens in the browser.

Below is my code in the manifest :

<activity android:name=".activities.VideoNewsDetailActivity"
        android:theme="@style/AppThemeActivity"
        android:configChanges="orientation|screenSize"
        >
        <!-- Add this new section to your Activity -->
        <intent-filter android:label="@string/videoNewsDetail">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <!-- Handle urls starting with "http://www.example.com/products" -->
            <data android:scheme="http"
                android:host="ddnews.apprikart.in"
                android:pathPrefix="/videos" />
            <!-- Handle local urls starting with "example://products" -->
            <data android:scheme="ddnews.apprikart"
                android:host="videos" />

        </intent-filter>
    </activity>

回答1:


This is how intent filter work. If more than 1 app can handle your intent, it will show an intent chooser. It's up to the user whether they want to open the link in your app or browser.

Your server should handle the playstore redirection part. For example your deeplink url is http://www.example.com/page/1. Now when the app is not installed the server can check if the url is called from a browser, then it should redirect the browser to the playstore's app url.




回答2:


@Eric B. is right. Even if you want only your app can open that link then you need to use custom scheme in intent-filter, like:

android:scheme="ddnews"

And need to build link like, ddnews://domain.com/dir/page.html



来源:https://stackoverflow.com/questions/41458390/deeplink-on-click-opens-intent-chooser-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!