程序未从 Android 电视的主屏幕启动

Program is not launching from home screen of Android TV

我正在尝试 select 主屏幕上的一个程序,但我总是收到提示 "Can't open this right now"。

这是我的清单以及我的节目是如何添加到电视提供商的。我将 intent uri、内部提供者 ID 和内容 ID 设置得非常详尽。

根据日志,我的接收器似乎从未启动过。

Class 将节目添加到电视提供商:

private static final Uri BASE_URI = Uri.parse(SCHEME + "://" + APPS_LAUNCH_HOST);
public static final String START_APP_ACTION_PATH = "startapp";
public static final String PLAY_VIDEO_ACTION_PATH = "playvideo";

public void addProgram(Movie movie) {
    ...
    PreviewProgram.Builder builder = new PreviewProgram.Builder()
            .setChannelId(channelId)
            .setTitle(movie.getTitle())
            .setDescription(movie.getDescription())
            .setDurationMillis(Long.valueOf(movie.getDuration()).intValue())
            .setType(TvContractCompat.PreviewPrograms.TYPE_MOVIE)
            .setIntentUri(Uri
                    .withAppendedPath(BASE_URI, PLAY_VIDEO_ACTION_PATH)
                    .buildUpon()
                    .appendPath(movieId)
                    .build())
            .setInternalProviderId(movieId)
            .setContentId(movieId)
    ...
}

public static long parseVideoId(Uri uri) {
    List<String> segments = uri.getPathSegments();
    if( segments.size() == 2 && PLAY_VIDEO_ACTION_PATH.equals(segments.get(0)) ) {
        return Long.valueOf(segments.get(1));
    }
    return -1L;
}

Android 清单

<receiver android:name=".PlayVideoReceiver"
        android:exported="true">
    <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:scheme="<scheme>"
            android:host="<host>"
            android:path="/playvideo" />
    </intent-filter>
</receiver>

我的清单有几个问题。

由于 uri 最终成为 scheme://host/playvideo/<id>,因此数据标记需要具有 android:pathPrefix 而不是 android:path,因为路径将是动态的并且比 /playvideo 更长。

其次,主屏幕通过调用 queryIntentForActivities() 搜索要启动的活动,所以我不得不将我的接收器更改为解析 Uri 并启动我的实际播放的 activity activity然后结束。

这应该是我的清单。

<activity android:name=".channels.PlayVideoActivity">
        <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:scheme="watchnextcodelab"
                android:host="com.example.android.watchnextcodelab"
                android:pathPrefix="/playvideo" />
        </intent-filter>
    </activity>