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.superapp.guessthelogoduoihinhbatthuonghieuvietnam.GCM.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from w  w  w. j a va 2  s  .  c om
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, SpashActivity.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.mipmap.ic_launcher)
    //                .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:br.com.commons.pushnotification.views.service.GcmCustomListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from   w w w  . j  a v a 2s  .co  m*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, HomeActivity.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.common_google_signin_btn_icon_dark).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.vurf.vurfx.controller.GCMListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 * @param message GCM message received./*from w  w  w  . j  av  a 2  s.com*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainMap.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)
            .setContentTitle("received 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.localhost.bracelet.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// w ww.j av  a  2  s  .com
 */
private void sendNotification(String message) {
    //Intent intent = new Intent(this, DeviceScanActivity.class);
    Intent intent = new Intent(this, DeviceControlActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 10 /* Request code */, 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("Bracelet Poke!").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setVibrate(new long[] { 0, 500 })
            .setContentIntent(pendingIntent);

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

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

From source file:kr.com.biligo.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from w w w  .ja v  a 2s  .  c  om
 */
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, 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.mipmap.icon).setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:com.layer.atlas.messenger.MessengerPushReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (debug)//from w  w  w .j  av a 2s  . c  o m
        Log.w(TAG, "onReceive() action: " + intent.getAction() + ", extras: "
                + MessengerApp.toString(intent.getExtras(), "\n", "\n"));
    if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
        if (debug)
            Log.w(TAG, "onReceive() Waking Up! due to action: " + intent.getAction());
        return;
    }

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

    String text = intent.getStringExtra("layer-push-message");
    Uri conversationId = (Uri) intent.getExtras().get("layer-conversation-id");
    String title = getTitle(context, conversationId);
    if (title == null)
        title = context.getResources().getString(R.string.app_name);

    Notification.Builder bld = new Notification.Builder(context);
    bld.setContentTitle(title).setContentText(text).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true)
            .setLights(Color.rgb(0, 255, 0), 100, 1900)
            .setDefaults(NotificationCompat.DEFAULT_SOUND | NotificationCompat.DEFAULT_VIBRATE);

    Intent chatIntent = new Intent(context, AtlasMessagesScreen.class);
    chatIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    chatIntent.putExtra(keys.CONVERSATION_URI, conversationId.toString());

    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, chatIntent,
            PendingIntent.FLAG_ONE_SHOT);

    bld.setContentIntent(resultPendingIntent);

    final Notification notification = bld.getNotification();

    try {
        // Group notifications by Conversation
        notificationService.notify(conversationId.hashCode(), notification);
    } catch (SecurityException ignored) {
        // 4.1.2 device required VIBRATE permission when in Vibrate mode. 
        // Fixed in 4.2.1 https://android.googlesource.com/platform/frameworks/base/+/cc2e849
    }
}

From source file:com.example.apple.sample_app.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//  w w w  .j a v a  2  s  .c  o m
 */
private void sendNotification(String message) // ? ? .//
{
    Intent intent = new Intent(this, MainTabActivity.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.mipmap.ic_launcher).setTicker("GCM Message") //?  .//
            .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.imaginabit.yonodesperdicion.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from   w  w  w  . j  a  v a  2 s  .  com
 */
private void sendNotification(String message) {
    Log.d(TAG, "sendNotification() called with: " + "message = [" + 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);

    //TODO : change small icon
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_local_offer).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.licenta.android.licenseapp.gcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///from w  w w . ja v a  2  s .  co m
private void sendNotification(String messageBody) {
    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_action_panic).setContentTitle("FCM Message").setContentText(messageBody)
            .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.android.elixr.ElixrGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from w  w w.j  a v  a  2s.c  o m
 */
private void sendNotification(ReportData reportData) {
    Intent intent = new Intent(this, ReportDataActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(REPORT_DATA_KEY, reportData);
    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(android.R.drawable.ic_menu_view).setContentTitle("GCM Message")
            .setContentText(reportData.getPatientName()).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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