Example usage for android.app Notification CATEGORY_RECOMMENDATION

List of usage examples for android.app Notification CATEGORY_RECOMMENDATION

Introduction

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

Prototype

String CATEGORY_RECOMMENDATION

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

Click Source Link

Document

Notification category: a specific, timely recommendation for a single thing.

Usage

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 {//ww w. j  ava  2 s .c  o  m
        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;
}

From source file:com.android.usbtuner.setup.TunerSetupActivity.java

/**
 * Sends the recommendation card to start the USB tuner TV input setup activity.
 *
 * @param context a {@link Context} instance
 *///from w  w  w  .  ja v a  2 s. c  om
private static void sendRecommendationCard(Context context) {
    Resources resources = context.getResources();
    String focusedTitle = resources.getString(R.string.ut_setup_recommendation_card_focused_title);
    String title = resources.getString(R.string.ut_setup_recommendation_card_title);
    Bitmap largeIcon = BitmapFactory.decodeResource(resources, R.drawable.recommendation_antenna);

    // Build and send the notification.
    Notification notification = new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(context)
            .setAutoCancel(false).setContentTitle(focusedTitle).setContentText(title).setContentInfo(title)
            .setCategory(Notification.CATEGORY_RECOMMENDATION).setLargeIcon(largeIcon)
            .setSmallIcon(resources.getIdentifier(TAG_ICON, TAG_DRAWABLE, context.getPackageName()))
            .setContentIntent(createPendingIntentForSetupActivity(context))).build();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFY_TAG, NOTIFY_ID, notification);
}

From source file:com.dogtim.recommendation.MainFragment.java

private Notification buildNotification() {
    PendingIntent intent = buildPendingIntent();
    Bundle extras = new Bundle();
    extras.putString("haha", "1234");
    Notification notification = new NotificationCompat.BigPictureStyle(
            new NotificationCompat.Builder(getActivity()).setAutoCancel(true).setContentTitle("Title")
                    .setContentText("Description").setLocalOnly(true).setOngoing(true)
                    .setColor(getResources().getColor(R.color.fastlane_background))
                    .setCategory(Notification.CATEGORY_RECOMMENDATION).setContentIntent(intent)
                    .setExtras(extras)).build();

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

    return notification;

}

From source file:com.example.android.xyztouristattractions.service.UtilityService.java

/**
 * Show the notification. Either the regular notification with wearable features
 * added to enhance, or trigger the full micro app on the wearable.
 *
 * @param cityId The city to trigger the notification for
 * @param microApp If the micro app should be triggered or just enhanced notifications
 *///  ww  w . j  ava 2 s  . c  o m
private void showNotification(String cityId, boolean microApp) {

    List<Attraction> attractions = ATTRACTIONS.get(cityId);

    if (microApp) {
        // If micro app we first need to transfer some data over
        sendDataToWearable(attractions);
    }

    // The first (closest) tourist attraction
    Attraction attraction = attractions.get(0);

    // Limit attractions to send
    int count = attractions.size() > Constants.MAX_ATTRACTIONS ? Constants.MAX_ATTRACTIONS : attractions.size();

    // Pull down the tourist attraction images from the network and store
    HashMap<String, Bitmap> bitmaps = new HashMap<>();
    try {
        for (int i = 0; i < count; i++) {
            bitmaps.put(attractions.get(i).name,
                    Glide.with(this).load(attractions.get(i).imageUrl).asBitmap()
                            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                            .into(Constants.WEAR_IMAGE_SIZE, Constants.WEAR_IMAGE_SIZE).get());
        }
    } catch (InterruptedException | ExecutionException e) {
        Log.e(TAG, "Error fetching image from network: " + e);
    }

    // The intent to trigger when the notification is tapped
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            DetailActivity.getLaunchIntent(this, attraction.name), PendingIntent.FLAG_UPDATE_CURRENT);

    // The intent to trigger when the notification is dismissed, in this case
    // we want to clear remote notifications as well
    PendingIntent deletePendingIntent = PendingIntent.getService(this, 0,
            getClearRemoteNotificationsIntent(this), 0);

    // Construct the main notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmaps.get(attraction.name))
                    .setBigContentTitle(attraction.name).setSummaryText(getString(R.string.nearby_attraction)))
            .setLocalOnly(microApp).setContentTitle(attraction.name)
            .setContentText(getString(R.string.nearby_attraction))
            .setSmallIcon(R.drawable.ic_stat_maps_pin_drop).setContentIntent(pendingIntent)
            .setDeleteIntent(deletePendingIntent).setColor(getResources().getColor(R.color.colorPrimary))
            .setCategory(Notification.CATEGORY_RECOMMENDATION).setAutoCancel(true);

    if (!microApp) {
        // If not a micro app, create some wearable pages for
        // the other nearby tourist attractions.
        ArrayList<Notification> pages = new ArrayList<Notification>();
        for (int i = 1; i < count; i++) {

            // Calculate the distance from current location to tourist attraction
            String distance = Utils.formatDistanceBetween(Utils.getLocation(this), attractions.get(i).location);

            // Construct the notification and add it as a page
            pages.add(new NotificationCompat.Builder(this).setContentTitle(attractions.get(i).name)
                    .setContentText(distance).setSmallIcon(R.drawable.ic_stat_maps_pin_drop)
                    .extend(new NotificationCompat.WearableExtender()
                            .setBackground(bitmaps.get(attractions.get(i).name)))
                    .build());
        }
        builder.extend(new NotificationCompat.WearableExtender().addPages(pages));
    }

    // Trigger the notification
    NotificationManagerCompat.from(this).notify(Constants.MOBILE_NOTIFICATION_ID, builder.build());
}

From source file:com.asburymotors.android.disneysocal.service.UtilityService.java

/**
 * Show the notification. Either the regular notification with wearable features
 * added to enhance, or trigger the full micro app on the wearable.
 *
 * @param cityId The city to trigger the notification for
 * @param microApp If the micro app should be triggered or just enhanced notifications
 *//* www  . jav  a  2s . com*/
private void showNotification(String cityId, boolean microApp) {

    List<Attraction> attractions = ATTRACTIONS.get(cityId);

    if (microApp) {
        // If micro app we first need to transfer some data over
        sendDataToWearable(attractions);
    }

    // The first (closest) tourist attraction
    Attraction attraction = attractions.get(0);

    // Limit attractions to send
    int count = attractions.size() > Constants.MAX_ATTRACTIONS ? Constants.MAX_ATTRACTIONS : attractions.size();

    // Pull down the tourist attraction images from the network and store
    HashMap<String, Bitmap> bitmaps = new HashMap<>();
    try {
        for (int i = 0; i < count; i++) {
            bitmaps.put(attractions.get(i).name,
                    Glide.with(this).load(attractions.get(i).imageUrl).asBitmap()
                            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                            .into(Constants.WEAR_IMAGE_SIZE, Constants.WEAR_IMAGE_SIZE).get());
        }
    } catch (InterruptedException | ExecutionException e) {
        Log.e(TAG, "Error fetching image from network: " + e);
    }

    // The intent to trigger when the notification is tapped
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            DetailActivity.getLaunchIntent(this, attraction.name), PendingIntent.FLAG_UPDATE_CURRENT);

    // The intent to trigger when the notification is dismissed, in this case
    // we want to clear remote notifications as well
    PendingIntent deletePendingIntent = PendingIntent.getService(this, 0,
            getClearRemoteNotificationsIntent(this), 0);

    // Construct the main notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmaps.get(attraction.name))
                    .setBigContentTitle(attraction.name).setSummaryText(getString(R.string.nearby_attraction)))
            .setLocalOnly(microApp).setContentTitle(attraction.name)
            .setContentText(getString(R.string.nearby_attraction))
            .setSmallIcon(R.drawable.ic_stat_maps_pin_drop).setContentIntent(pendingIntent)
            .setDeleteIntent(deletePendingIntent)
            .setColor(getResources().getColor(R.color.colorPrimary, getTheme()))
            .setCategory(Notification.CATEGORY_RECOMMENDATION).setAutoCancel(true);

    if (!microApp) {
        // If not a micro app, create some wearable pages for
        // the other nearby tourist attractions.
        ArrayList<Notification> pages = new ArrayList<Notification>();
        for (int i = 1; i < count; i++) {

            // Calculate the distance from current location to tourist attraction
            String distance = Utils.formatDistanceBetween(Utils.getLocation(this), attractions.get(i).location);

            // Construct the notification and add it as a page
            pages.add(new NotificationCompat.Builder(this).setContentTitle(attractions.get(i).name)
                    .setContentText(distance).setSmallIcon(R.drawable.ic_stat_maps_pin_drop)
                    .extend(new NotificationCompat.WearableExtender()
                            .setBackground(bitmaps.get(attractions.get(i).name)))
                    .build());
        }
        builder.extend(new NotificationCompat.WearableExtender().addPages(pages));
    }

    // Trigger the notification
    NotificationManagerCompat.from(this).notify(Constants.MOBILE_NOTIFICATION_ID, builder.build());
}

From source file:com.android.tv.tuner.setup.TunerSetupActivity.java

/**
 * Sends the recommendation card to start the tuner TV input setup activity.
 *
 * @param context a {@link Context} instance
 *///from w ww.jav  a 2s  . com
private static void sendRecommendationCard(Context context, String contentTitle, String contentText,
        Bitmap largeIcon) {
    // Build and send the notification.
    Notification notification = new NotificationCompat.BigPictureStyle(new NotificationCompat.Builder(context)
            .setAutoCancel(false).setContentTitle(contentTitle).setContentText(contentText)
            .setContentInfo(contentText).setCategory(Notification.CATEGORY_RECOMMENDATION)
            .setLargeIcon(largeIcon)
            .setSmallIcon(
                    context.getResources().getIdentifier(TAG_ICON, TAG_DRAWABLE, context.getPackageName()))
            .setContentIntent(createPendingIntentForSetupActivity(context))).build();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFY_TAG, NOTIFY_ID, notification);
}