点击网络链接应用即会打开

时间:2015-10-19 11:23:37

标签: java android uri deep-linking

我正在尝试构建一个应用程序,如果我点击链接,我的应用程序(如果已安装)将打开。但它不起作用,不知道为什么。它总是重定向到google.com

我的清单文件

<activity   android:name=".DeeplinkingActivity"
            android:label="@string/app_name"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@android:style/Theme.Holo.NoActionBar">
            <intent-filter android:label="@string/app_name">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs that begin with "http://example.com/soham" -->
                <data android:scheme="http"
                    android:host="example.com"
                    android:pathPrefix="/soham" />
                <data android:scheme="http"
                    android:host="www.example.com"
                    android:pathPrefix="/soham" />
            </intent-filter>
        </activity> 

我的test.html

<a href="intent://scan/#Intent;scheme=http;package=soham.com.deeplinking;S.browser_fallback_url=http%3A%2F%2Fgoogle.com;end"></a>

我认为问题出在html文件中。有什么帮助吗?

2 个答案:

答案 0 :(得分:1)

您的链接不正确,您正在使用Android Intents with Chrome example的主机。您需要使用host中配置的pathPrefixAndroidManifest.xml

您的hostexample.compathPrefix/soham,该链接将成为:

<a href="intent://example.com/soham#Intent;scheme=http;package=soham.com.deeplinking;S.browser_fallback_url=http%3A%2F%2Fgoogle.com;end">Deeplink</a>

答案 1 :(得分:0)

试试这个:这适用于我的应用:

注意:在您的启动器活动代码中写下以下代码

<intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter android:label="@string/app_name" >
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <!-- Accepts URIs that begin with "example://WRITE YOUR HOST NAME” -->
            <data
                android:host="index.html"
                android:scheme="WRITE YOUR HOST NAME" />
        </intent-filter>
        <intent-filter android:label="@string/app_name" >
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <!-- Accepts URIs that begin with "http://example.com/WRITE YOUR HOST NAME” -->
            <data
                android:host="WRITE YOUR HOST NAME.com"
                android:pathPrefix="/index.html"
                android:scheme="http" />
        </intent-filter>
        <intent-filter android:label="@string/app_name" >
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="WRITE YOUR HOST NAME" />
        </intent-filter>
相关问题