Example usage for android.content Intent setFlags

List of usage examples for android.content Intent setFlags

Introduction

In this page you can find the example usage for android.content Intent setFlags.

Prototype

public @NonNull Intent setFlags(@Flags int flags) 

Source Link

Document

Set special flags controlling how this intent is handled.

Usage

From source file:com.siahmsoft.soundroid.sdk7.services.UploadService.java

/**
 * Show a notification while this service is running.
 *///from  w  w w .  jav  a2  s.  c  om
private void showNotification(String text) {
    // Set the icon, scrolling text and timestamp
    Notification notification = new Notification(R.drawable.uploadtocloud, text, System.currentTimeMillis());

    // The PendingIntent to launch our activity if the user selects this notification
    Intent i = new Intent(this, MeActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    /*Bundle bundle = new Bundle();
    bundle.putInt("idTrack", soundcloudTrack.getmIdTrack());
    i.putExtras(bundle);*/

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(this, "Uploading...", text, contentIntent);

    // We show this for as long as our service is processing a command.
    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL;
    notification.number = totalUploads;

    // Send the notification.
    // We use a string id because it is a unique number.  We use it later to cancel.
    mNM.notify(777, notification);
}

From source file:com.android.mail.browse.AttachmentActionHandler.java

public void shareAttachments(ArrayList<Parcelable> uris) {
    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    intent.setType("image/*");
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

    try {/*from w  w  w .  j a va 2  s  . com*/
        mContext.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        // couldn't find activity for SEND_MULTIPLE intent
        LogUtils.e(LOG_TAG, "Couldn't find Activity for intent", e);
    }
}

From source file:com.oakesville.mythling.MediaPagerActivity.java

@Override
public void onBackPressed() {
    if (EpgActivity.class.getName().equals(backTo) || FireTvEpgActivity.class.getName().equals(backTo)) {
        Intent a = new Intent(Intent.ACTION_MAIN);
        a.addCategory(Intent.CATEGORY_HOME);
        a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(a);/*from w w w.java 2  s  .  c o m*/
    } else if (modeSwitch) {
        modeSwitch = false;
        Intent intent = new Intent(this, MediaPagerActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
    } else {
        super.onBackPressed();
    }
}

From source file:edu.mines.letschat.GcmIntentService.java

private void sendNotification(String msg, String senderID) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra(MainActivity.EXTRA_NOTIFICATION_RETRIEVE, senderID);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    notificationCounter++;//w w  w  . ja va2s  .c  o m

    if (messages.size() > 1) {
        msg = msg + "...";
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setVibrate(new long[] { 0, 500, 250, 500, 250 }).setLights(Color.BLUE, 200, 200)
            .setSmallIcon(R.drawable.logo).setContentTitle("Let's Chat Notification")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setNumber(notificationCounter)
            .setTicker(msg).setContentText(msg);

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    // Sets a title for the Inbox style big view
    inboxStyle.setBigContentTitle("Unread messages (" + notificationCounter + "):");
    // Moves events into the big view
    ArrayList<String> temp = new ArrayList<String>();
    for (int i = 0; i < 5; ++i) {
        if (i == messages.size()) {
            break;
        }
        temp.add(messages.get(i));
    }
    Collections.reverse(temp);
    messages = temp;
    for (String s : messages) {
        inboxStyle.addLine(s);
    }

    mBuilder.setStyle(inboxStyle);

    mBuilder.setAutoCancel(true);
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    //        AwesomeAdapter.animate = true;
}

From source file:com.qubittech.feelknit.app.MainActivity.java

private Intent GetIntent(Class cls) {
    Intent intent = new Intent(MainActivity.this, cls);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("EXIT", true);
    return intent;
}

From source file:net.kourlas.voipms_sms.Notifications.java

public void showNotifications(List<String> contacts) {
    if (!(ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationsActivity)) {
        Conversation[] conversations = Database.getInstance(applicationContext)
                .getConversations(preferences.getDid());
        for (Conversation conversation : conversations) {
            if (!conversation.isUnread() || !contacts.contains(conversation.getContact())
                    || (ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationActivity
                            && ((ConversationActivity) ActivityMonitor.getInstance().getCurrentActivity())
                                    .getContact().equals(conversation.getContact()))) {
                continue;
            }//from w  ww .  ja  va2s.  co  m

            String smsContact = Utils.getContactName(applicationContext, conversation.getContact());
            if (smsContact == null) {
                smsContact = Utils.getFormattedPhoneNumber(conversation.getContact());
            }

            String allSmses = "";
            String mostRecentSms = "";
            boolean initial = true;
            for (Message message : conversation.getMessages()) {
                if (message.getType() == Message.Type.INCOMING && message.isUnread()) {
                    if (initial) {
                        allSmses = message.getText();
                        mostRecentSms = message.getText();
                        initial = false;
                    } else {
                        allSmses = message.getText() + "\n" + allSmses;
                    }
                } else {
                    break;
                }
            }

            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(applicationContext);

            notificationBuilder.setContentTitle(smsContact);
            notificationBuilder.setContentText(mostRecentSms);
            notificationBuilder.setSmallIcon(R.drawable.ic_chat_white_24dp);
            notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
            notificationBuilder
                    .setSound(Uri.parse(Preferences.getInstance(applicationContext).getNotificationSound()));
            notificationBuilder.setLights(0xFFAA0000, 1000, 5000);
            if (Preferences.getInstance(applicationContext).getNotificationVibrateEnabled()) {
                notificationBuilder.setVibrate(new long[] { 0, 250, 250, 250 });
            } else {
                notificationBuilder.setVibrate(new long[] { 0 });
            }
            notificationBuilder.setColor(0xFFAA0000);
            notificationBuilder.setAutoCancel(true);
            notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(allSmses));

            Bitmap largeIconBitmap;
            try {
                largeIconBitmap = MediaStore.Images.Media.getBitmap(applicationContext.getContentResolver(),
                        Uri.parse(Utils.getContactPhotoUri(applicationContext, conversation.getContact())));
                largeIconBitmap = Bitmap.createScaledBitmap(largeIconBitmap, 256, 256, false);
                largeIconBitmap = Utils.applyCircularMask(largeIconBitmap);
                notificationBuilder.setLargeIcon(largeIconBitmap);
            } catch (Exception ignored) {

            }

            Intent intent = new Intent(applicationContext, ConversationActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(applicationContext.getString(R.string.conversation_extra_contact),
                    conversation.getContact());
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(applicationContext);
            stackBuilder.addParentStack(ConversationActivity.class);
            stackBuilder.addNextIntent(intent);
            notificationBuilder
                    .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT));

            Intent replyIntent = new Intent(applicationContext, ConversationQuickReplyActivity.class);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
            } else {
                //noinspection deprecation
                replyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            }
            replyIntent.putExtra(applicationContext.getString(R.string.conversation_extra_contact),
                    conversation.getContact());
            PendingIntent replyPendingIntent = PendingIntent.getActivity(applicationContext, 0, replyIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);
            NotificationCompat.Action.Builder replyAction = new NotificationCompat.Action.Builder(
                    R.drawable.ic_reply_white_24dp,
                    applicationContext.getString(R.string.notifications_button_reply), replyPendingIntent);
            notificationBuilder.addAction(replyAction.build());

            Intent markAsReadIntent = new Intent(applicationContext, MarkAsReadReceiver.class);
            markAsReadIntent.putExtra(applicationContext.getString(R.string.conversation_extra_contact),
                    conversation.getContact());
            PendingIntent markAsReadPendingIntent = PendingIntent.getBroadcast(applicationContext, 0,
                    markAsReadIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            NotificationCompat.Action.Builder markAsReadAction = new NotificationCompat.Action.Builder(
                    R.drawable.ic_drafts_white_24dp,
                    applicationContext.getString(R.string.notifications_button_mark_read),
                    markAsReadPendingIntent);
            notificationBuilder.addAction(markAsReadAction.build());

            int id;
            if (notificationIds.get(conversation.getContact()) != null) {
                id = notificationIds.get(conversation.getContact());
            } else {
                id = notificationIdCount++;
                notificationIds.put(conversation.getContact(), id);
            }
            NotificationManager notificationManager = (NotificationManager) applicationContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(id, notificationBuilder.build());
        }
    }
}

From source file:net.openid.appauthdemo.TokenActivity.java

@MainThread
private void signOut() {
    // discard the authorization and token state, but retain the configuration and
    // dynamic client registration (if applicable), to save from retrieving them again.
    AuthState currentState = mStateManager.getCurrent();
    AuthState clearedState = new AuthState(currentState.getAuthorizationServiceConfiguration());
    if (currentState.getLastRegistrationResponse() != null) {
        clearedState.update(currentState.getLastRegistrationResponse());
    }//from ww  w.  ja  v  a 2s .  c  o m
    mStateManager.replace(clearedState);

    Intent mainIntent = new Intent(this, LoginActivity.class);
    mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(mainIntent);
    finish();
}

From source file:com.microsoft.firstapp.AuthService.java

/**
 * Handles logging the user out including: -deleting cookies so their login
 * with a provider won't be cached in the web view -removing the userdata
 * from the shared preferences -setting the current user object on the
 * client to logged out -optionally redirects to the login page if requested
 * /*from www .  j  a  v a2  s.  c  o  m*/
 * @param shouldRedirectToLogin
 */
public void logout(boolean shouldRedirectToLogin) {
    // Clear the cookies so they won't auto login to a provider again
    CookieSyncManager.createInstance(mContext);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    // Clear the user id and token from the shared preferences
    SharedPreferences settings = mContext.getSharedPreferences("UserData", 0);
    SharedPreferences.Editor preferencesEditor = settings.edit();
    preferencesEditor.clear();
    preferencesEditor.commit();
    // Clear the user and return to the auth activity
    mClient.logout();
    // Take the user back to the auth activity to relogin if requested
    if (shouldRedirectToLogin) {
        Intent logoutIntent = new Intent(mContext, LogInActivity.class);
        logoutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(logoutIntent);
    }
}

From source file:com.appnexus.opensdk.ANNativeAdResponse.java

private boolean openNativeIntent(String url, Context context) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {/*w  w  w . jav a2  s  .co m*/
        context.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        Clog.w(Clog.baseLogTag, Clog.getString(R.string.opening_url_failed, url));
        return false;
    }
}