尝试启用深度链接到Android应用程序,测试意图无法启动活动

时间:2014-09-08 22:10:53

标签: android android-intent android-manifest deep-linking

我尝试启用深层链接,以便某些链接启动我的应用。

我读了这个turotial https://developer.android.com/training/app-indexing/deep-linking.html并且非常接近但是当我尝试使用adb将VIEW意图发送到应用程序时测试它我只是得到了错误

Error: Activity not started, unable to resolve Intent { act=android.intent.actio
n.VIEW dat=example://gizmos flg=0x10000000 pkg=com.myapp.DeepLinkActivity }

DeepLinkActivity.java

public class DeepLinkActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getIntent().getAction() == Intent.ACTION_VIEW) {
        Uri uri = getIntent().getData();

    }

  }
}

Android Manifest宣布深层链接活动

<activity android:name="com.myapp.DeepLinkActivity" >
        <intent-filter>

            <action android:name="android.intent.action.VIEW" />

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


            <data
                android:host="gizmos"
                android:scheme="example" />
            <!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
            <data
                android:host="www.example.com"
                android:pathPrefix="gizmos"
                android:scheme="http" />
        </intent-filter>
    </activity>

发送视图意图的ADB命令

adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.myapp.DeepLinkActivity

但我认为我甚至不需要完整的活动路径

adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.myapp

4 个答案:

答案 0 :(得分:6)

尝试完全跳过包参数。我有完全相同的问题而且有效。

adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos"

答案 1 :(得分:2)

在你的清单中,你将你的计划定义为&#34; http&#34;但是在你的意图构造函数中,你正在使用&#34;示例。&#34;

答案 2 :(得分:1)

问题是您有两种深度链接的意图过滤器:

<activity
    android:name="app.myActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait">
    <intent-filter>
        <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://gizmos”-->
        <data
            android:host="gizmos"
            android:scheme="example" />
    </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:host="www.example.com"
            android:pathPrefix="/gizmos"
            android:scheme="http" />
        <!-- note that the leading "/" is required for pathPrefix-->                
    </intent-filter>
</activity>

您将能够在ADB shell上使用它们。请参阅我的完整答案here

答案 3 :(得分:0)

只需尝试以下操作

Command:
adb shell am start -d your-deep-link

Example:
adb shell am start -d rmagazine://opensetting/v1
相关问题