Program is not launching from home screen of Android TV

Viewed 654

I am trying to select a program on the home screen but I keep getting a toast that says "Can't open this right now".

Here is my manifest and how my program get's added to the TV Provider. I am setting the intent uri, internal provider id and content id to be thorough.

Based on the logs, it looks like my receiver is never launched.

Class that adds programs to the 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 Manifest

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

There were a couple of problems with my manifest.

Since the uri ends up being scheme://host/playvideo/<id> the data tag needs to have android:pathPrefix instead of android:path since the path will be dynamic and longer than just /playvideo.

Secondly, the home screen searches for actives to launch by calling queryIntentForActivities() so I had to change my receiver into an activity that parsed the Uri and launch my actual playback activity then finishes.

This is what my manifest should have been instead.

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