Example usage for android.app PendingIntent FLAG_ONE_SHOT

List of usage examples for android.app PendingIntent FLAG_ONE_SHOT

Introduction

In this page you can find the example usage for android.app PendingIntent FLAG_ONE_SHOT.

Prototype

int FLAG_ONE_SHOT

To view the source code for android.app PendingIntent FLAG_ONE_SHOT.

Click Source Link

Document

Flag indicating that this PendingIntent can be used only once.

Usage

From source file:com.pg.app.gcm.MyGcmListenerService.java

private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_icon_info).setContentTitle("GCM Message").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.onsemi.matrix.android.pushnotification.PNGcmListenerService.java

private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("GCM Message")
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.sqldexter.gcmnetworking.MyGcmListenerService.java

private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setColor(Color.parseColor("#e65100")).setSmallIcon(R.drawable.ic_notification)
            .setContentTitle("GCM Message").setContentText(message).setAutoCancel(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:disono.webmons.com.utilities.library.CloudMessage.FireBase.FMessaging.java

private void sendNotification(String messageBody) {
    MeModel meModel = new MeModel();

    // received only if user is authenticated
    if (meModel.check()) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(this.setTitle).setContentText(messageBody)
                .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0, notificationBuilder.build());
    }/*  ww  w. j  a  va 2 s  . c  o m*/

    Log.i(TAG, "New notification received.");
}

From source file:com.votzapp.app.MyGcmListenerService.java

/**
 * Called when message is received.//from   ww  w .j  ava  2  s.co  m
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
//And show mobile notification
@Override
public void onMessageReceived(String from, Bundle data) {
    String body = data.getString("body");
    String title = data.getString("title");

    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setContentText(body)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);
    notificationManager.notify(1, mBuilder.build());

}

From source file:com.jsw.callcastreceiver.Call_BroadCastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();//from  w  ww . j  a v a  2  s.c om
    if (bundle != null) {
        String state = bundle.getString(TelephonyManager.EXTRA_STATE);
        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
            String number = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

            Intent newIntent = new Intent(context, Telefon_Activity.class);
            newIntent.putExtra("number", number);
            PendingIntent pending = PendingIntent.getActivity(context, CALLNOTIFICATION, newIntent,
                    PendingIntent.FLAG_ONE_SHOT);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
            builder.setContentTitle("Telefon Activity");
            builder.setSmallIcon(R.mipmap.ic_launcher);
            builder.setContentText("Incoming call from: " + number);
            builder.setDefaults(Notification.DEFAULT_VIBRATE);
            builder.setDefaults(Notification.DEFAULT_LIGHTS);
            //Aadir el objeto PendingItem a la notificicacion
            builder.setContentIntent(pending);
            //Aadir la notificacion al Manager
            NotificationManager notify = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notify.notify(CALLNOTIFICATION, builder.build());
        }
    }
}

From source file:felixwiemuth.lincal.util.Util.java

/**
 * Show an error dialog in the given context (or optionally a notification if a dialog cannot be
 * shown).//from ww w.j a  va 2s .c  o  m
 *
 * @param title        resource id for the title text
 * @param message      the dialog's main message
 * @param notification whether to show a notification when a dialog cannot be shown in the given
 *                     context (clicking the notification will start {@link
 *                     CalendarListActivity}) - if {@code false} and the dialog cannot be shown,
 *                     the application will crash
 * @param context      context where the dialog should be displayed
 */
public static void showErrorDialog(int title, String message, boolean notification, Context context) {
    if (notification && !(context instanceof Activity)) {
        Intent intent = new Intent(context, CalendarListActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setSmallIcon(android.R.drawable.stat_sys_warning).setContentTitle(context.getString(title))
                .setContentText(message).setContentIntent(pendingIntent).setAutoCancel(true);

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        nm.notify((int) System.currentTimeMillis(), nb.build());
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setPositiveButton(R.string.dialog_error_dismiss, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        }).setTitle(title).setMessage(message);
        builder.show();
    }
}

From source file:br.org.projeto.vigilante.push.MyGcmListenerService.java

private void sendNotification(String message) {
    Intent intent = MainActivity_.intent(this).get();
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(getString(R.string.app_name)).setSmallIcon(R.drawable.ic_stat_action_account_child)
            .setColor(getResources().getColor(R.color.colorPrimary))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, notificationBuilder.build());
}

From source file:jahirfiquitiva.iconshowcase.utilities.utils.NotificationUtils.java

public static void sendFirebaseNotification(Context context, Class mainActivity, Map<String, String> data,
        String title, String content) {
    Preferences mPrefs = new Preferences(context);
    if (!(mPrefs.getNotifsEnabled()))
        return;//from  w w  w.ja v a  2 s  .c  o m

    int ledColor = ThemeUtils.darkOrLight(context, R.color.dark_theme_accent, R.color.light_theme_accent);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notifications).setContentTitle(title).setTicker(title)
            .setContentText(content).setAutoCancel(true).setOngoing(false).setColor(ledColor);

    Intent intent = new Intent();
    int flag = 0;
    if (mPrefs.getLauncherIconShown()) {
        intent = new Intent(context, mainActivity);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (data != null) {
            if (data.size() > 0) {
                for (int i = 0; i < data.size(); i++) {
                    String[] dataValue = data.toString().replace("{", "").replace("}", "").split(",")[i]
                            .split("=");
                    Timber.d("Key: " + dataValue[0] + " - Value: " + dataValue[1]);
                    intent.putExtra(dataValue[0], dataValue[1]);
                }
            }
        }
        flag = PendingIntent.FLAG_ONE_SHOT;
    }
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /* Request code
                                                                       */, intent, flag);
    notificationBuilder.setContentIntent(pendingIntent);

    Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    Resources resources = context.getResources(), systemResources = Resources.getSystem();

    notificationBuilder.setSound(mPrefs.getNotifsSoundEnabled() ? ringtoneUri : null);
    notificationBuilder.setVibrate(mPrefs.getNotifsVibrationEnabled() ? new long[] { 500, 500 } : null);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = notificationBuilder.build();

    if (mPrefs.getNotifsEnabled()) {
        notification.flags |= Notification.FLAG_SHOW_LIGHTS;
        notification.ledARGB = ledColor;
        notification.ledOnMS = resources.getInteger(
                systemResources.getIdentifier("config_defaultNotificationLedOn", "integer", "android"));
        notification.ledOffMS = resources.getInteger(
                systemResources.getIdentifier("config_defaultNotificationLedOff", "integer", "android"));
    } else {
        notification.ledOnMS = 0;
        notification.ledOffMS = 0;
    }

    notificationManager.notify(1 /* ID of notification */, notificationBuilder.build());
}

From source file:com.umanji.umanjiapp.gcm.GcmListenerService.java

private void sendNotification(Bundle data) {
    String title = data.getString("title");
    String text = data.getString("text");

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("bundle", data);

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_umanji_launcher).setContentTitle(title).setContentText(text)
            .setAutoCancel(true)// w  w  w  .  j a  va  2s .c  o  m
            //                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

}