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.lokesh.FCMNotification.plugin.MyFirebaseMessagingService.java

public void createNotification(Context context, RemoteMessage.Notification message) {
    saveNotificationOnSharedPreferences(message.getBody(), context);
    Intent intent = new Intent(this, FCMNotificationHandlerActivity.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(this.getApplicationInfo().icon).setContentTitle(message.getTitle())
            .setContentText(message.getBody()).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

}

From source file:kz.bapps.e_concrete.service.ChatGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from   w  ww.j  av  a  2  s  . com*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, AuthActivity.class);
    //intent.setAction(MainActivity.ACTION_CHAT);
    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(android.R.drawable.ic_dialog_email).setContentTitle(EConcrete.appName)
            .setContentText(message.length() > 20 ? message.substring(0, 20) + "..." : message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:com.example.gcmproject.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.  com*/
 */
private void sendNotification(String message, String code) {
    Intent intent = null;
    if (code.equals("1")) { // ?   
        intent = new Intent(this, MainActivity.class); //  
    } else if (code.equals("2")) {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(message)); //    ?  ?  message ? uri .
    }

    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); // GCM   

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

From source file:com.cs180.ucrtinder.youwho.Messenger.MessengerPushReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (debug)/* w w w.  j a v a  2  s.  c o  m*/
        Log.w(TAG, "onReceive() action: " + intent.getAction() + ", extras: "
                + YouWhoApplication.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.leo.cattle.presentation.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./* w  w w. j a va  2 s.  com*/
 */
private void sendNotification(Bundle bundle) {
    String message = bundle.getString("message");
    Intent intent = new Intent(this, SignInActivity.class);
    Bundle b = new Bundle();
    //b.putString("username", AndroidApplication.sessionUser.getFullName());
    b.putString("to", bundle.getString("username"));
    b.putString("session_id", bundle.getString("chatSessionId"));
    b.putString("type", bundle.getString("type"));
    intent.putExtras(b);
    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_whats_hot).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.teamappjobs.appjobs.FCM.MyFirebaseMessagingService.java

/**
 * Create and show notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///from ww  w.  ja  v  a 2 s.c  o m
private void onNovaPromocao(String messageBody) {
    VitrineJson vitrineJson = new VitrineJson();
    Promocao promocao = vitrineJson.JsonToPromocao(messageBody);

    //  Intent intent = new Intent(this, MainActivity.class);
    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("From", "notifyFragSigo");

    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);
    long[] v = { 100, 500, 100, 500 }; //Vibrao
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)

            .setSmallIcon(R.drawable.heart_notif).setContentTitle(promocao.getNome())
            .setContentText(promocao.getDescricao()).setAutoCancel(true).setSound(defaultSoundUri).setVibrate(v)
            .setContentIntent(pendingIntent);

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

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

From source file:com.fitticket.model.services.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from  ww  w .  j a  v  a2 s.  co m
 * @param type
 */
private void sendNotification(String message, String type) {
    Intent intent;
    if (!TextUtils.isEmpty(type) && type.equalsIgnoreCase("confirmation")) {
        intent = new Intent(this, MainActivity.class);
        intent.putExtra(MainActivity.SHOW_UPCOMING, true);
    } else {
        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.fit).setContentTitle(getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(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.iems5722.group9.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from ww w.j  a v  a2  s  .co m*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, com.iems5722.group9.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.q).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.pixtory.app.pushnotification.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from w ww  .  j  a va  2s  .  c o  m
 */
private void sendNotification(String message, String image) {
    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);
    Bitmap b = null;
    try {
        URL url = new URL(image);
        b = BitmapFactory.decodeStream(url.openConnection().getInputStream());
    } catch (Exception e) {
        e.printStackTrace();
    }
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.notif).setContentTitle("pixtory").setContentText(message)
            .setAutoCancel(true);

    //.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.pixtory))
    if (b != null)
        notificationBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(b));

    notificationBuilder.setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    AmplitudeLog.logEvent(new AmplitudeLog.AppEventBuilder(App_Notification_Shown)
            .put(AppConstants.USER_ID, Utils.getUserId(getApplicationContext())).build());
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.erhuoapp.erhuo.activity.BaseActivity.java

/**
 * ???????????//from  w  w  w. ja  v  a 2s  .  com
 * ????
 * @param message
 */
protected void notifyNewMessage(EMMessage message) {
    //????(app??demo??)
    //?setShowNotificationInbackgroup:false(false???sdk??)
    if (!EasyUtils.isAppRunningForeground(this)) {
        return;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(getApplicationInfo().icon).setWhen(System.currentTimeMillis()).setAutoCancel(true);

    String ticker = CommonUtils.getMessageDigest(message, this);
    String st = getResources().getString(R.string.expression);
    if (message.getType() == Type.TXT)
        ticker = ticker.replaceAll("\\[.{2,3}\\]", st);
    //????
    mBuilder.setTicker(message.getFrom() + ": " + ticker);

    //pendingintent?2.3bug
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, notifiId, intent,
            PendingIntent.FLAG_ONE_SHOT);
    mBuilder.setContentIntent(pendingIntent);

    Notification notification = mBuilder.build();
    notificationManager.notify(notifiId, notification);
    notificationManager.cancel(notifiId);
}