尝试启用与Android应用的深度链接,测试意图无法启动活动

Bri*_*ian 4 android deep-linking android-manifest android-intent

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

我读了这个教程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 }
Run Code Online (Sandbox Code Playgroud)

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();

    }

  }
}
Run Code Online (Sandbox Code Playgroud)

Android Manifest宣布Deeplink活动

<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>
Run Code Online (Sandbox Code Playgroud)

ADB命令发送视图意图

adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.myapp.DeepLinkActivity
Run Code Online (Sandbox Code Playgroud)

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

adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.myapp
Run Code Online (Sandbox Code Playgroud)

Kam*_*rna 7

尝试完全跳过软件包参数。我有完全相同的问题,它可以工作。

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


sou*_*ris 3

在清单中,您将方案定义为“http”,但在意图构造函数中,您使用的是“示例”。