【问题标题】:Program is not launching from home screen of Android TV程序未从 Android TV 的主屏幕启动
【发布时间】:2017-11-22 17:31:07
【问题描述】:

我正在尝试在主屏幕上选择一个程序,但我不断收到提示“现在无法打开它”的提示。

这是我的清单以及我的节目是如何添加到 TV Provider 的。我将意图 uri、内部提供商 ID 和内容 ID 设置为彻底。

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

将节目添加到 TV Provider 的类:

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>

【问题讨论】:

    标签: android-tv


    【解决方案1】:

    我的清单存在一些问题。

    由于 uri 最终为 scheme://host/playvideo/&lt;id&gt;,因此数据标签需要使用 android:pathPrefix 而不是 android:path,因为路径将是动态的并且比 /playvideo 更长。

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

    这应该是我的清单。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-10
      相关资源
      最近更新 更多