首页 文章

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

提问于
浏览
2

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

我读了这个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 declaring deeplink activity

<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 回答

  • 1

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

  • 2

    从Android Manifest中注释掉第二个数据部分 . 根据google深层链接文档:

    “Intent过滤器可能只包含URI模式的单个数据元素 . 创建单独的intent过滤器以捕获其他URI模式 . ”

  • 4

    尝试完全跳过包参数 . 我有完全相同的问题,它的工作原理 .

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

  • 4

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

    <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

相关问题