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.jefftharris.passwdsafe.sync.lib.AccountChooserDlg.java

/** Handle a selected account */
private void onAccountSelected(String accountName) {
    Bundle args = getArguments();//from   ww w.  j ava 2 s  .  c om
    int requestCode = args.getInt("requestCode");

    int result;
    Intent intent = new Intent();
    if (accountName != null) {
        intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName);
        result = Activity.RESULT_OK;
    } else {
        result = Activity.RESULT_CANCELED;
    }

    PendingIntent pendIntent = getActivity().createPendingResult(requestCode, intent,
            PendingIntent.FLAG_ONE_SHOT);
    try {
        pendIntent.send(result);
    } catch (PendingIntent.CanceledException e) {
        Log.e(TAG, "intent send failed", e);
    }
}

From source file:com.example.llh_pc.it_support.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
        /*from  ww w.ja v  a  2s .co  m*/
 */
private void sendNotification(String message, String avatar, String name) {
    Intent intent = new Intent(this, frmTabHost.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.its_logo_72x72px).setContentTitle("IT Support").setContentText(name)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(++Flags.number_notification /* ID of notification */,
            notificationBuilder.build());
}

From source file:com.hugosama.samalinne.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from www . j  a  va 2s  .  c o 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);

    Bitmap image = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Samalinne").setContentText(messageBody)
            .setAutoCancel(true).setLargeIcon(image).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:com.jefftharris.passwdsafe.sync.onedrive.OnedriveProvider.java

/**
 * Start the process of linking to an account
 *//*from   w  w w .ja v  a2 s  .  co  m*/
@Override
public void startAccountLink(final FragmentActivity activity, final int requestCode) {
    Runnable loginTask = new Runnable() {
        @Override
        public void run() {
            itsAuthClient.login(activity, null, new AuthListener() {
                @Override
                public void onAuthComplete(AuthStatus status, AuthSession session, Object userState) {
                    PasswdSafeUtil.dbginfo(TAG, "login ok status %s, sess [%s]", status, session);

                    switch (status) {
                    case CONNECTED: {
                        Intent intent = new Intent();
                        PendingIntent pendIntent = activity.createPendingResult(requestCode, intent,
                                PendingIntent.FLAG_ONE_SHOT);
                        try {
                            pendIntent.send(Activity.RESULT_OK);
                        } catch (PendingIntent.CanceledException e) {
                            Log.e(TAG, "login intent send failed", e);
                        }
                        break;
                    }
                    case NOT_CONNECTED:
                    case UNKNOWN: {
                        Log.e(TAG, "Auth complete, bad status: " + status);
                        break;
                    }
                    }
                }

                @Override
                public void onAuthError(AuthException exception, Object userState) {
                    Log.e(TAG, "Auth error", exception);
                }
            });
        }
    };

    if (isAccountAuthorized()) {
        unlinkAccount(loginTask);
    } else {
        loginTask.run();
    }
}

From source file:be.ehb.fallwear.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*ww w. j  a v a  2  s  .co m*/
 */
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.rip.roomies.service.MessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param message FCM message body received.
 *//*from   ww  w .  j a v  a 2s .  c  om*/
private void sendNotification(String title, String message) {

    Intent intent;
    if (MyApplication.isActivityVisible()) {
        switch (title) {
        case "Duty Completion":
        case "Duty Reminder":
            intent = new Intent(this, ListAllDuties.class);
            break;
        case "Shared Item Completion":
        case "Shared Item Reminder":
            intent = new Intent(this, ListAllGoods.class);
            break;
        case "Bill Reminder":
            intent = new Intent(this, Bills.class);
            break;
        default:
            intent = new Intent(this, Home.class);
        }
    } else {
        intent = new Intent(this, SplashScreen.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)
            .setLargeIcon((BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher)))
            .setContentTitle(title).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.sendbird.android.CS185Project.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from  w  ww . j  av a2s  .  com*/
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.sendbird_ic_launcher).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:com.maxwen.wallpaper.firebase.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 */// w w w  . ja v  a  2 s.  c  om
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, WallpaperBoardActivity.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_drawer_wallpapers).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.example.android.elizachat.ResponderService.java

private void showNotification() {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Sent: " + mLastResponse);
    }/* w  ww  .  j  av a 2  s.com*/
    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_MIN);

    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:javasign.com.dompetsehat.base.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from w w w.  j  a v a  2 s. co m*/
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, NewMainActivity.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.logo_ds).setContentTitle("DompetSehat Notification")
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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