Example usage for android.content Intent cloneFilter

List of usage examples for android.content Intent cloneFilter

Introduction

In this page you can find the example usage for android.content Intent cloneFilter.

Prototype

public @NonNull Intent cloneFilter() 

Source Link

Document

Make a clone of only the parts of the Intent that are relevant for filter matching: the action, data, type, component, and categories.

Usage

From source file:org.patneu.simpleflash.CameraOnNotification.java

/**
 * Returns an instance of this application's standard {@link Notification},
 * referred to as the 'CameraOnNotification'. <br/><br/>
 * /* w  w  w  .  j a va 2s  .c o  m*/
 * This method gets a Notification to tell the user that the camera's
 * flashlight is still turned on, since unintentionally leaving it on may
 * damage the user's device. <br/><br/>
 * 
 * <b>Note:</b> Although this method is named 'getInstance', it doesn't
 *              actually use any constructor of this class (which wouldn't
 *              have sense anyway, since the class doesn't extend the
 *              Notification class. Instead, it internally builds a new
 *              Notification using the {@link NotificationCompat.Builder}
 *              class.
 * 
 * @param context the {@link Context} of the Activity that wants to {@link
 *                SimpleFlash.NotifyManager#sendNotification(int,
 *                android.app.Notification) send} this Notification
 * @param intent should be the {@link Intent} that originally started the
 *               sending Activity, as provided by {@link
 *               Activity#getIntent()}
 * @param click defines what to do if the user clicks this Notification,
 *              should be one of the static 'NOTIFICATION_XXX' values
 * @param cancel defines what to do if the user cancels this Notification,
 *               should be one of the static 'NOTIFICATION_XXX' values
 * 
 * @return an instance of this application's standard Notification with the
 *         specified behavior
 * 
 * @since Version 1.0
 */
public static Notification getInstance(Context context, Intent intent, int click, int cancel) {
    NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(context);
    nBuilder.setSmallIcon(R.drawable.ic_stat_notify);
    nBuilder.setContentTitle(context.getString(R.string.app_name));
    nBuilder.setContentText(context.getString(R.string.camera_on_notification_text));
    nBuilder.setTicker(context.getString(R.string.camera_on_notification_text));
    nBuilder.setPriority(NotificationCompat.PRIORITY_LOW);

    PendingIntent contentPending = null;
    PendingIntent deletePending = null;
    if (click != NOTIFICATION_NOTHING) {
        if (click == NOTIFICATION_RESUME) {
            contentPending = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        }
        if (click == NOTIFICATION_FINISH) {
            Intent finishIntent = intent.cloneFilter();
            finishIntent.setAction(ACTION_FINISH);
            contentPending = PendingIntent.getActivity(context, 0, finishIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
        }
        nBuilder.setContentIntent(contentPending);
    }
    if (cancel != NOTIFICATION_NOTHING) {
        if (cancel == NOTIFICATION_RESUME) {
            deletePending = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        }
        if (cancel == NOTIFICATION_FINISH) {
            Intent finishIntent = intent.cloneFilter();
            finishIntent.setAction(ACTION_FINISH);
            deletePending = PendingIntent.getActivity(context, 0, finishIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
        }
        nBuilder.setDeleteIntent(deletePending);
    }

    return nBuilder.build();
}