Example usage for android.app Notification EXTRA_BACKGROUND_IMAGE_URI

List of usage examples for android.app Notification EXTRA_BACKGROUND_IMAGE_URI

Introduction

In this page you can find the example usage for android.app Notification EXTRA_BACKGROUND_IMAGE_URI.

Prototype

String EXTRA_BACKGROUND_IMAGE_URI

To view the source code for android.app Notification EXTRA_BACKGROUND_IMAGE_URI.

Click Source Link

Document

#extras key: A android.content.ContentUris content URI pointing to an image that can be displayed in the background when the notification is selected.

Usage

From source file:com.example.android.dragonTV.recommendation.RecommendationBuilder.java

public Notification build() {

    Log.d(TAG, "Building notification - " + this.toString());

    Bundle extras = new Bundle();
    if (mBackgroundUri != null) {
        Log.d(TAG, "Background - " + mBackgroundUri);
        extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI, mBackgroundUri);
    }//from w  w w  . j  a  v  a 2 s .  com

    Notification notification = new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(mContext)
            .setContentTitle(mTitle).setContentText(mDescription).setPriority(mPriority).setLocalOnly(true)
            .setOngoing(true).setColor(mContext.getResources().getColor(R.color.fastlane_background))
            .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(mBitmap).setSmallIcon(mSmallIcon)
            .setContentIntent(mIntent).setExtras(extras)).build();

    return notification;
}

From source file:com.github.pedrovgs.tuentitv.recommendation.builder.RecommendationBuilder.java

public Notification build() throws IOException {
    if (notificationManager == null) {
        notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    }/* ww w .  ja  v  a2  s  .c o  m*/

    Bundle extras = new Bundle();
    if (backgroundUri != null) {
        extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI, backgroundUri);
    }

    Bitmap image = Picasso.with(context).load(imageUri).get();

    Notification notification = new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(context)
            .setContentTitle(title).setContentText(description).setPriority(priority).setLocalOnly(true)
            .setOngoing(true).setColor(context.getResources().getColor(R.color.primary_color))
            .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(image).setSmallIcon(smallIcon)
            .setContentIntent(pendingIntent).setExtras(extras)).build();

    notificationManager.notify(id, notification);
    notificationManager = null;
    return notification;
}

From source file:cm.aptoidetv.pt.RecommendationBuilder.java

public Notification build() throws IOException {

    Log.d(TAG, "Building notification - " + this.toString());

    if (mNotificationManager == null) {
        mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    }/*  www.j ava 2  s .co m*/

    Bundle extras = new Bundle();
    if (mBackgroundUri != null) {
        Log.d(TAG, "Background - " + mBackgroundUri);
        extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI, mBackgroundUri);
    }

    Bitmap image = Picasso.with(mContext).load(mImageUri)
            .resize(Utils.convertDpToPixel(mContext, CARD_WIDTH), Utils.convertDpToPixel(mContext, CARD_HEIGHT))
            .get();

    TypedArray typedArray = mContext.getTheme().obtainStyledAttributes(ThemePicker.getThemePicker(),
            new int[] { R.attr.brandColor });
    int brandColorResourceId = typedArray.getResourceId(0, 0);
    typedArray.recycle();

    Notification notification = new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(mContext)
            .setContentTitle(mTitle).setContentText(mDescription).setPriority(mPriority).setLocalOnly(true)
            .setOngoing(true).setColor(mContext.getResources().getColor(brandColorResourceId))
            .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(image).setSmallIcon(mSmallIcon)
            .setContentIntent(mIntent).setExtras(extras)).build();

    mNotificationManager.notify(mId, notification);
    mNotificationManager = null;
    return notification;
}

From source file:org.messic.android.smarttv.activities.recommendations.RecommendationBuilder.java

public Notification build() {

    Bundle extras = new Bundle();
    File bitmapFile = getNotificationBackground(mContext, mId);

    if (mBackgroundUri != null) {
        extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI,
                Uri.parse(BACKGROUND_URI_PREFIX + Long.toString(mId)).toString());
    }/*from  w  ww .j  a va  2s.c  o m*/

    // the following simulates group assignment into "Top", "Middle", "Bottom"
    // by checking mId and similarly sort order
    mGroupKey = (mId < 3) ? "Top" : (mId < 5) ? "Middle" : "Bottom";
    mSort = (mId < 3) ? "1.0" : (mId < 5) ? "0.7" : "0.3";

    // save bitmap into files for content provider to serve later
    try {
        bitmapFile.createNewFile();
        FileOutputStream fOut = new FileOutputStream(bitmapFile);
        mBitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut);
        fOut.flush();
        fOut.close();
    } catch (IOException ioe) {
        Log.d(TAG, "Exception caught writing bitmap to file!", ioe);
    }

    Notification notification = new NotificationCompat.BigPictureStyle(
            new NotificationCompat.Builder(mContext).setAutoCancel(true).setContentTitle(mTitle)
                    .setContentText(mDescription).setPriority(mPriority).setLocalOnly(true).setOngoing(true)
                    /*
                    groupKey (optional): Can be used to group together recommendations, so
                    they are ranked by the launcher as a separate group. Can be useful if the
                    application has different sources for recommendations, like "trending",
                    "subscriptions", and "new music" categories for YouTube, where the user can
                    be more interested in recommendations from one group than another.
                     */
                    .setGroup(mGroupKey)
                    /*
                    sortKey (optional): A float number between 0.0 and 1.0, used to indicate
                    the relative importance (and sort order) of a single recommendation within
                    its specified group. The recommendations will be ordered in decreasing
                    order of importance within a given group.
                     */
                    .setSortKey(mSort)
                    //  .setColor(mContext.getResources().getColor(R.color.fastlane_background))
                    .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(mBitmap)
                    .setSmallIcon(mSmallIcon).setContentIntent(mIntent).setExtras(extras)).build();

    Log.d(TAG, "Building notification - " + this.toString());

    return notification;
}

From source file:com.androideasyapps.phoenix.recommend.RecommendationBuilder.java

public Notification build() throws IOException {

    Log.d(TAG, "Building notification - " + this.toString());

    if (mNotificationManager == null) {
        mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    }/*  www  .ja  v a  2s  .com*/

    Bundle extras = new Bundle();
    if (mBackgroundUri != null) {
        Log.d(TAG, "Background - " + mBackgroundUri);
        extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI, mBackgroundUri);
    }

    Bitmap image = Picasso.with(mContext).load(mImageUri)
            .resize(Utils.convertDpToPixel(mContext, CARD_WIDTH), Utils.convertDpToPixel(mContext, CARD_HEIGHT))
            .get();

    Notification notification = new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(mContext)
            .setContentTitle(mTitle).setContentText(mDescription).setPriority(mPriority).setLocalOnly(true)
            .setOngoing(true).setColor(mContext.getResources().getColor(R.color.fastlane_background))
            .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(image).setSmallIcon(mSmallIcon)
            .setContentIntent(mIntent).setExtras(extras)).build();

    mNotificationManager.notify(mId, notification);
    mNotificationManager = null;
    return notification;
}

From source file:com.example.android.tvleanback.recommendation.RecommendationBuilder.java

public Notification build() {

    Bundle extras = new Bundle();
    File bitmapFile = getNotificationBackground(mContext, mId);

    if (mBackgroundUri != null) {
        extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI,
                Uri.parse(BACKGROUND_URI_PREFIX + Integer.toString(mId)).toString());
    }//from  w ww .  j ava  2  s .c  o m

    // the following simulates group assignment into "Top", "Middle", "Bottom"
    // by checking mId and similarly sort order
    mGroupKey = (mId < 3) ? "Top" : (mId < 5) ? "Middle" : "Bottom";
    mSort = (mId < 3) ? "1.0" : (mId < 5) ? "0.7" : "0.3";

    // save bitmap into files for content provider to serve later
    try {
        bitmapFile.createNewFile();
        FileOutputStream fOut = new FileOutputStream(bitmapFile);
        mBitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut);
        fOut.flush();
        fOut.close();
    } catch (IOException ioe) {
        Log.d(TAG, "Exception caught writing bitmap to file!", ioe);
    }

    Notification notification = new NotificationCompat.BigPictureStyle(
            new NotificationCompat.Builder(mContext).setAutoCancel(true).setContentTitle(mTitle)
                    .setContentText(mDescription).setPriority(mPriority).setLocalOnly(true).setOngoing(true)
                    /*
                    groupKey (optional): Can be used to group together recommendations, so
                    they are ranked by the launcher as a separate group. Can be useful if the
                    application has different sources for recommendations, like "trending",
                    "subscriptions", and "new music" categories for YouTube, where the user can
                    be more interested in recommendations from one group than another.
                     */
                    .setGroup(mGroupKey)
                    /*
                    sortKey (optional): A float number between 0.0 and 1.0, used to indicate
                    the relative importance (and sort order) of a single recommendation within
                    its specified group. The recommendations will be ordered in decreasing
                    order of importance within a given group.
                     */
                    .setSortKey(mSort).setColor(mContext.getResources().getColor(R.color.fastlane_background))
                    .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(mBitmap)
                    .setSmallIcon(mSmallIcon).setContentIntent(mIntent).setExtras(extras)).build();

    Log.d(TAG, "Building notification - " + this.toString());

    return notification;
}

From source file:butter.droid.tv.service.recommendation.RecommendationBuilder.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Notification build() throws IOException {
    if (VersionUtils.isLollipop()) {

        Log.d(TAG, "Building notification - " + this.toString());

        if (mNotificationManager == null) {
            mNotificationManager = (NotificationManager) mContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
        }//from ww w .j a  v a 2s.  com

        Bundle extras = new Bundle();
        if (mBackgroundUri != null) {
            extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI, mBackgroundUri);
        }

        Bitmap image = Picasso.with(mContext).load(mImageUri)
                .resize((int) mContext.getResources().getDimension(R.dimen.card_width),
                        (int) mContext.getResources().getDimension(R.dimen.card_height))
                .get();

        Notification notification = new NotificationCompat.BigPictureStyle(
                new NotificationCompat.Builder(mContext).setContentTitle(mTitle).setContentText(mDescription)
                        .setPriority(mPriority).setLocalOnly(true).setOngoing(true)
                        .setColor(mContext.getResources().getColor(R.color.primary))
                        .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(image)
                        .setSmallIcon(mSmallIcon).setContentIntent(mIntent).setExtras(extras)).build();

        mNotificationManager.notify(mId, notification);
        mNotificationManager = null;
        return notification;
    }

    return null;
}

From source file:us.nineworlds.serenity.core.RecommendationBuilder.java

public Notification build() throws IOException {

    Log.d(TAG, "Building notification - " + this.toString());

    if (mNotificationManager == null) {
        mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    }/*  w  w  w . j a  va  2s . c  om*/

    Bundle extras = new Bundle();
    if (mBackgroundUri != null) {
        if (backgroundContentUri != null) {
            extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI, backgroundContentUri);

        }
    }

    ImageLoader imageLoader = serenityImageLoader.getImageLoader();
    Bitmap image = imageLoader.loadImageSync(mImageUri, new ImageSize(176, 313),
            serenityImageLoader.getSycnOptions());

    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);

    builder = builder.setContentTitle(mTitle).setContentText(mDescription).setPriority(mPriority)
            .setOngoing(true).setLocalOnly(true).setColor(cardColor)
            .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(image).setSmallIcon(mSmallIcon)
            .setContentIntent(mIntent).setExtras(extras);

    Notification notification = new NotificationCompat.BigPictureStyle(builder).build();

    try {
        mNotificationManager.notify(mId, notification);
    } catch (Exception ex) {
        Log.e(getClass().getName(), ex.getMessage(), ex);
    }
    mNotificationManager = null;
    return notification;
}

From source file:com.corochann.androidtvapptutorial.recommendation.RecommendationBuilder.java

public Notification build() {

    Bundle extras = new Bundle();
    File bitmapFile = getNotificationBackground(mContext, mId);

    if (mBackgroundBitmap != null) {
        Log.d(TAG, "making URI for mBackgroundBitmap");
        extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI,
                Uri.parse(BACKGROUND_URI_PREFIX + Integer.toString(mId)).toString());
    } else {/*from   w ww .j a v  a2s  .c om*/
        Log.w(TAG, "mBackgroundBitmap is null");
    }

    // the following simulates group assignment into "Top", "Middle", "Bottom"
    // by checking mId and similarly sort order
    mGroupKey = (mId < 3) ? "Group1" : (mId < 5) ? "Group2" : "Group3";
    mSort = (mId < 3) ? "1.0" : (mId < 5) ? "0.7" : "0.3";

    // save bitmap into files for content provider to serve later
    try {
        bitmapFile.createNewFile();
        FileOutputStream fOut = new FileOutputStream(bitmapFile);
        mBackgroundBitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut); // <- background bitmap must be created by mBackgroundUri, and not  mCardImageBitmap
        fOut.flush();
        fOut.close();
    } catch (IOException ioe) {
        Log.d(TAG, "Exception caught writing bitmap to file!", ioe);
    }

    Notification notification = new NotificationCompat.BigPictureStyle(
            new NotificationCompat.Builder(mContext).setAutoCancel(true).setContentTitle(mTitle)
                    .setContentText(mDescription).setPriority(mPriority).setLocalOnly(true).setOngoing(true)
                    /*
                    groupKey (optional): Can be used to group together recommendations, so
                    they are ranked by the launcher as a separate group. Can be useful if the
                    application has different sources for recommendations, like "trending",
                    "subscriptions", and "new music" categories for YouTube, where the user can
                    be more interested in recommendations from one group than another.
                     */
                    .setGroup(mGroupKey)
                    /*
                    sortKey (optional): A float number between 0.0 and 1.0, used to indicate
                    the relative importance (and sort order) of a single recommendation within
                    its specified group. The recommendations will be ordered in decreasing
                    order of importance within a given group.
                     */
                    .setSortKey(mSort).setColor(mContext.getResources().getColor(R.color.fastlane_background))
                    .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(mCardImageBitmap)
                    .setSmallIcon(mSmallIcon).setContentIntent(mIntent).setExtras(extras)).build();

    Log.d(TAG, "Building notification - " + this.toString());

    return notification;
}