0

I implemented the recommendation in FireTV but it's not working. I am not able to see the recommendation row in FireTV

I used this code in FireTV recommendation. I am using contentrecommendation instead of NotificationCompat.Builder.

 if (mNotifManager == null) {
        mNotifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    }

@Override
protected void onHandleIntent(Intent intent) {
    // Generate recommendations, but only if recommendations are enabled
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    if (!sharedPreferences.getBoolean(getString(R.string.pref_key_recommendations), true)) {
        Log.d(TAG, "Recommendations disabled");
        mNotifManager.cancelAll();
        return;
    }
    Resources res = getResources();

 int cardWidth = res.getDimensionPixelSize(R.dimen.card_width);
    int cardHeight = res.getDimensionPixelSize(R.dimen.card_height);
    ContentRecommendation.Builder builder = new ContentRecommendation.Builder()
            .setBadgeIcon(R.drawable.videos_by_google_icon);

    Cursor cursor = getContentResolver().query(
            VideoContract.VideoEntry.CONTENT_URI,
            null, // projection
            null, // selection
            null, // selection clause
            "RANDOM() LIMIT " + MAX_RECOMMENDATIONS // sort order
    );
if (cursor != null && cursor.moveToNext()) {
        try {
            do {
                Video video = (Video) mVideoCursorMapper.convert(cursor);
                int id = Long.valueOf(video.id).hashCode();

                builder.setIdTag("Video" + id)
                        .setTitle(video.title)
                        .setText(getString(R.string.popular_header))
                        .setContentIntentData(ContentRecommendation.INTENT_TYPE_ACTIVITY,
                                buildPendingIntent(video, id), 0, null);

                Bitmap bitmap = Glide.with(getApplication())
                        .asBitmap()
                        .load(video.cardImageUrl)
                        .submit(cardWidth, cardHeight) // Only use for synchronous .get()
                        .get();
                builder.setContentImage(bitmap);

                // Create an object holding all the information used to recommend the content.
                ContentRecommendation rec = builder.build();
                Notification notification = rec.getNotificationObject(getApplicationContext());

                if (BuildConfig.DEBUG) Log.d(TAG, "Recommending video " + video.title);

                // Recommend the content by publishing the notification.
                mNotifManager.notify(id, notification);
            } while (cursor.moveToNext());
        } catch (InterruptedException | ExecutionException e) {
            Log.e(TAG, "Could not create recommendation.", e);
        } finally {
            cursor.close();
        }
    }
}

private Intent buildPendingIntent(Video video, int id) {
    Intent detailsIntent = new Intent(this, VideoDetailsActivity.class);
    detailsIntent.putExtra(VideoDetailsActivity.VIDEO, video);
    detailsIntent.putExtra(VideoDetailsActivity.NOTIFICATION_ID, id);
    detailsIntent.setAction(Long.toString(video.id));

    return detailsIntent;
}

// Manifest file

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<uses-permission android:name="com.android.providers.tv.permission.READ_EPG_DATA" />

<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA" />

<provider
            android:name=".recommendation.VideoProvider"
            android:authorities="${packageName}"
            android:permission="${applicationId}.ACCESS_VIDEO_DATA"
            android:exported="true">
            <path-permission android:pathPrefix="/search"
              android:readPermission="android.permission.GLOBAL_SEARCH" 
            />
 </provider>


<receiver
            android:name=".recommendation.RecommendationReceiver"
            android:enabled="true"
            android:exported="false">
            <intent-filter>
       <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
 </receiver>


<service     android:name=".recommendation.UpdateRecommendationsService"
            android:enabled="true" />



I am using reciever and service for recommendation in the manifest file.

0 Answers0