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:br.ufc.quixada.dsdm.myapplicationtestemulttabs.googleGCM.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*  www .  j a v  a  2 s .c  om*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivityTabMensagens.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.mensageiro_icon).setContentTitle("MENSSAGEIRO").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.donteatalone.asheeshsharma.capstone_porject2.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from  w w w.  java2 s . c  o m*/
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, LoginChatActivity.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.sample_img2).setContentTitle("SendBird").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:fr.bmartel.android.tictactoe.gcm.MyGcmListenerService.java

/**
 * Called when message is received.//  w  w  w.j  av  a 2  s. c o  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]
@Override
public void onMessageReceived(String from, Bundle data) {

    String message = data.getString("message");

    if (from.startsWith("/topics/" + GameSingleton.DEVICE_ID)) {
        Log.d(TAG, "Message: " + message);

        try {

            JSONObject object = new JSONObject(message);

            ArrayList<String> eventItem = new ArrayList<>();
            eventItem.add(object.toString());

            broadcastUpdateStringList(BroadcastFilters.EVENT_MESSAGE, eventItem);

            if (!GameSingleton.activityForeground) {

                if (object.has(RequestConstants.DEVICE_MESSAGE_TOPIC)
                        && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID)
                        && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)) {

                    GameMessageTopic topic = GameMessageTopic
                            .getTopic(object.getInt(RequestConstants.DEVICE_MESSAGE_TOPIC));

                    ChallengeMessage challengeMessage = new ChallengeMessage(topic,
                            object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID),
                            object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME));

                    Log.i(TAG, "challenged by " + challengeMessage.getChallengerName() + " : "
                            + challengeMessage.getChallengerId());

                    Intent intent2 = new Intent(this, DeviceListActivity.class);
                    intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent2,
                            PendingIntent.FLAG_ONE_SHOT);
                    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Fight!")
                            .setContentText("challenged by " + challengeMessage.getChallengerName())
                            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);
                    NotificationManager notificationManager = (NotificationManager) getSystemService(
                            Context.NOTIFICATION_SERVICE);
                    notificationManager.notify(new Random().nextInt(9999), notificationBuilder.build());

                    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                    boolean isScreenOn = pm.isScreenOn();
                    if (isScreenOn == false) {
                        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
                                | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyLock");
                        wl.acquire(10000);
                        PowerManager.WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                                "MyCpuLock");
                        wl_cpu.acquire(10000);
                    }

                    GameSingleton.pendingChallengeMessage = challengeMessage;
                    GameSingleton.pendingChallenge = true;
                }
            }

        } catch (JSONException e) {
            e.printStackTrace();

        }
    }
}

From source file:com.example.android.wearable.elizachat.ResponderService.java

private void showNotification() {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Sent: " + mLastResponse);
    }/*from   w  w  w. j a  va  2  s .  co  m*/
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setContentTitle(getString(R.string.eliza)).setContentText(mLastResponse)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza))
            .setSmallIcon(R.drawable.bg_eliza).setPriority(NotificationCompat.PRIORITY_DEFAULT);

    Intent intent = new Intent(ACTION_RESPONSE);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
    Notification notification = builder.extend(new NotificationCompat.WearableExtender()
            .addAction(new NotificationCompat.Action.Builder(R.drawable.ic_full_reply,
                    getString(R.string.reply), pendingIntent).addRemoteInput(
                            new RemoteInput.Builder(EXTRA_REPLY).setLabel(getString(R.string.reply)).build())
                            .build()))
            .build();
    NotificationManagerCompat.from(this).notify(0, notification);
}

From source file:asia.covisoft.goom.gcm.GoOmUserGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*  w  w  w.  ja va  2s  .  c  om*/
 */
private void sendNotification(String message, Driverconfirm response) {

    Intent intent = new Intent(this, HistoryDetailsActivity.class);
    trandingId = response.getTradingid();
    intent.putExtra(Extras.TRADING_ID, trandingId);
    intent.putExtra(Extras.HISTORY_STATE, false);
    if (response.getValue().equals("tip")) {
        intent.putExtra(Extras.REQUEST_TIP, true);
        intent.putExtra(Extras.MAX_TIP, response.getMaxsuggest());
        intent.putExtra(Extras.MIN_TIP, response.getMinsuggest());
        cancelTip();
    }

    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(getString(R.string.app_name_full))
            .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.androdevlinux.percy.bitfly.Core.Services.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from w  w w  . j av a  2  s .  c  om*/
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_menu_camera).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.bevyios.gcm.BevyGcmListenerService.java

private void sendNotification(Bundle bundle) {
    Resources resources = getApplication().getResources();
    String packageName = getApplication().getPackageName();
    Class intentClass = getMainActivityClass();
    if (intentClass == null) {
        return;// ww  w  .  j  av  a 2s. co m
    }

    if (applicationIsRunning()) {
        Intent i = new Intent("BevyGCMReceiveNotification");
        i.putExtra("bundle", bundle);
        sendBroadcast(i);
        return;
    }

    int resourceId = resources.getIdentifier(bundle.getString("largeIcon"), "mipmap", packageName);

    Intent intent = new Intent(this, intentClass);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    //Bitmap largeIcon = BitmapFactory.decodeResource(resources, resourceId);

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

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            //.setLargeIcon(largeIcon)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("title").setContentText("content")
            .setAutoCancel(false).setSound(defaultSoundUri)
            //.setTicker(bundle.getString("ticker"))
            .setCategory(NotificationCompat.CATEGORY_CALL).setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
            .setPriority(NotificationCompat.PRIORITY_HIGH).setContentIntent(pendingIntent);

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

    Notification notif = notificationBuilder.build();
    notif.defaults |= Notification.DEFAULT_VIBRATE;
    notif.defaults |= Notification.DEFAULT_SOUND;
    notif.defaults |= Notification.DEFAULT_LIGHTS;

    notificationManager.notify(0, notif);
}

From source file:com.bosco.noticeboard.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param note Notice received from server.
 *//*from   w  w w.  j  a  v a 2s . c o m*/
private void sendNotification(Notice note) {
    Intent intent = new Intent(this, NoticeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("Notice", note);
    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(note.subject).setSmallIcon(R.drawable.normal_bell).setContentText(note.content)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

    if (note.priority == 1) {
        notificationBuilder.setColor(getResources().getColor(R.color.icon_normal));
    } else if (note.priority == 2) {
        notificationBuilder.setColor(getResources().getColor(R.color.icon_important));
    }

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

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

From source file:com.korchid.msg.firebase.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///w  ww .  j a v a2  s . c om
private void sendNotification(String messageBody) {
    Log.d(TAG, "sendNotification");
    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_logo).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.nghianh.giaitriviet.util.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param remoteMessage FCM remoteMessage
 *//*from w  w w.j  a  v a  2s . co  m*/
private void sendNotification(RemoteMessage remoteMessage) {
    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);
    String imageUri = remoteMessage.getData().get("image");
    String message = remoteMessage.getData().get("message");
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setLargeIcon(getBitmapfromUrl(imageUri)).setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(remoteMessage.getNotification().getTitle()).setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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