Example usage for android.content Intent FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

List of usage examples for android.content Intent FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

Introduction

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

Prototype

int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

To view the source code for android.content Intent FLAG_ACTIVITY_RESET_TASK_IF_NEEDED.

Click Source Link

Document

If set, and this activity is either being started in a new task or bringing to the top an existing task, then it will be launched as the front door of the task.

Usage

From source file:com.dm.material.dashboard.candybar.adapters.IntentAdapter.java

private Intent addIntentExtra(@NonNull Intent intent) {
    intent.setType("message/rfc822");
    if (mRequest.getStream().length() > 0) {
        File zip = new File(mRequest.getStream());
        Uri uri = FileHelper.getUriFromFile(mContext, mContext.getPackageName(), zip);
        if (uri == null)
            uri = Uri.fromFile(zip);//w  w  w.  ja v a 2s. c  o  m
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }

    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { mContext.getResources().getString(R.string.dev_email) });
    intent.putExtra(Intent.EXTRA_SUBJECT, mRequest.getSubject());
    intent.putExtra(Intent.EXTRA_TEXT, mRequest.getText());
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    return intent;
}

From source file:org.android.gcm.client.GcmIntentService.java

private Intent getPushactIntent(int flags) {
    Intent intent = new Intent();
    intent.setClassName(pushpak, pushact);
    intent.setFlags(flags | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NO_HISTORY
            | Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}

From source file:com.gumgoose.app.quakebuddy.EarthquakeActivity.java

private static void openGooglePlay(Context context) {
    // Open Google Play app or browser equivalent to QuakeBuddy's page
    Intent rateIntent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("market://details?id=" + context.getPackageName()));
    boolean marketFound = false;

    // Find all apps able to handle the rating intent
    final List<ResolveInfo> otherApps = context.getPackageManager().queryIntentActivities(rateIntent, 0);
    for (ResolveInfo otherApp : otherApps) {
        // Locate the Google Play app
        if (otherApp.activityInfo.applicationInfo.packageName.equals("com.android.vending")) {
            ActivityInfo otherAppActivity = otherApp.activityInfo;
            ComponentName componentName = new ComponentName(otherAppActivity.applicationInfo.packageName,
                    otherAppActivity.name);
            // Ensure Google Play opens on a new task
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            // Reparent the task if needed
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            // Handle if Google Play is already open
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            // Ensure that only Google Play catches the intent
            rateIntent.setComponent(componentName);
            context.startActivity(rateIntent);
            marketFound = true;/*from w  w  w  . j av  a  2 s  .  com*/
            break;
        }
    }
    if (!marketFound) {
        // Google Play was not found, open web browser instead
        Intent webIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/details?id=" + context.getPackageName()));
        context.startActivity(webIntent);
    }
}

From source file:com.dogtim.recommendation.MainFragment.java

private void openPlayStore() {
    Intent launchIntent = getActivity().getPackageManager().getLaunchIntentForPackage("com.android.vending");
    launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    startActivity(launchIntent);/*from w  w w . j a  v a  2s.c om*/
}

From source file:org.simlar.SimlarService.java

Notification createNotification(final SimlarStatus status) {
    String text = null;/*  www  . j a  va2  s. c  om*/

    if (mNotificationActivity == null || (status != SimlarStatus.ONGOING_CALL && !mCreatingAccount)) {
        mNotificationActivity = MainActivity.class;
    }

    final PendingIntent activity = PendingIntent.getActivity(this, 0,
            new Intent(this, mNotificationActivity).addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED), 0);

    if (status == SimlarStatus.ONGOING_CALL) {
        text = String.format(getString(status.getNotificationTextId()), mSimlarCallState.getDisplayName());
    } else if (mCreatingAccount) {
        text = getString(R.string.notification_simlar_status_creating_account);
        if (!Util.isNullOrEmpty(PreferencesHelper.getMySimlarIdOrEmptyString())) {
            text += ": " + String.format(getString(status.getNotificationTextId()),
                    PreferencesHelper.getMySimlarIdOrEmptyString());
        }
    } else {
        text = String.format(getString(status.getNotificationTextId()),
                PreferencesHelper.getMySimlarIdOrEmptyString());
    }

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setSmallIcon(status.getNotificationIcon());
    notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.app_logo));
    notificationBuilder.setContentTitle(getString(R.string.app_name));
    notificationBuilder.setContentText(text);
    notificationBuilder.setTicker(text);
    notificationBuilder.setOngoing(true);
    notificationBuilder.setContentIntent(activity);
    notificationBuilder.setWhen(System.currentTimeMillis());
    return notificationBuilder.build();
}

From source file:org.floens.chan.ui.service.WatchNotifier.java

/**
 * Create a notification with the supplied parameters.
 * The style of the big notification is InboxStyle, a list of text.
 *
 * @param tickerText    The tickertext to show, or null if no tickertext should be shown.
 * @param contentTitle  The title of the notification
 * @param contentText   The content of the small notification
 * @param contentNumber The contentInfo and number, or -1 if not shown
 * @param expandedLines A list of lines for the big notification, or null if not shown
 * @param makeSound     Should the notification make a sound
 * @param target        The target pin, or null to open the pinned pane on tap
 * @return/*from   ww  w .  ja  v  a2s.  com*/
 */
@SuppressWarnings("deprecation")
private Notification getNotificationFor(String tickerText, String contentTitle, String contentText,
        int contentNumber, List<CharSequence> expandedLines, boolean light, boolean makeSound, Pin target) {
    Intent intent = new Intent(this, ChanActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    intent.putExtra("pin_id", target == null ? -1 : target.id);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    if (makeSound) {
        builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    }

    if (light) {
        long watchLed = ChanPreferences.getWatchLed();
        if (watchLed >= 0) {
            builder.setLights((int) watchLed, 1000, 1000);
        }
    }

    builder.setContentIntent(pendingIntent);

    if (tickerText != null) {
        tickerText = tickerText.substring(0, Math.min(tickerText.length(), 50));
    }

    builder.setTicker(tickerText);
    builder.setContentTitle(contentTitle);
    builder.setContentText(contentText);

    if (contentNumber >= 0) {
        builder.setContentInfo(Integer.toString(contentNumber));
        builder.setNumber(contentNumber);
    }

    builder.setSmallIcon(R.drawable.ic_stat_notify);

    Intent pauseWatching = new Intent(this, WatchNotifier.class);
    pauseWatching.putExtra("pause_pins", true);

    PendingIntent pauseWatchingPending = PendingIntent.getService(this, 0, pauseWatching,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.addAction(R.drawable.ic_action_pause, getString(R.string.watch_pause_pins), pauseWatchingPending);

    if (expandedLines != null) {
        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
        for (CharSequence line : expandedLines.subList(Math.max(0, expandedLines.size() - 10),
                expandedLines.size())) {
            style.addLine(line);
        }
        style.setBigContentTitle(contentTitle);
        builder.setStyle(style);
    }

    return builder.getNotification();
}

From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java

/**
 * ????/*from   ww  w .j  a va2 s.  com*/
 * 
 * @param mContext
 *            
 * @param TagClass
 *            ???
 * @param iconResId
 *            ??
 * @param iconName
 *            ??
 */
public static void addShortCut2Desktop(Context mContext, Class<?> TagClass, int iconResId, String iconName) {
    SharedPreferences sp = mContext.getSharedPreferences("appinfo", Context.MODE_PRIVATE);
    if (!sp.getBoolean("shortcut_flag_icon", false)) {
        sp.edit().putBoolean("shortcut_flag_icon", true).commit();
        LogUtil.d("shortcut", "first create successfull");
    } else {
        LogUtil.d("shortcut", "no created");
        return;
    }

    String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
    Intent intent = new Intent();
    intent.setClass(mContext, TagClass);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT);
    Parcelable icon = Intent.ShortcutIconResource.fromContext(mContext, iconResId);// ???
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, iconName);// ??
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);// ??
    addShortcut.putExtra("duplicate", false);// ????
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// ??

    mContext.sendBroadcast(addShortcut);// ??
}

From source file:com.linkbubble.MainService.java

private void showUnhideHiddenNotification() {
    Intent unhideIntent = new Intent(this, NotificationUnhideActivity.class);
    unhideIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
            | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent unhidePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
            unhideIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    /*Intent showContentViewIntent = new Intent(this, NotificationShowContentActivity.class);
    showContentViewIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent showContentViewPendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), showContentViewIntent, PendingIntent.FLAG_UPDATE_CURRENT);*/

    Intent closeAllIntent = new Intent(this, NotificationCloseAllActivity.class);
    closeAllIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
            | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent closeAllPendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
            closeAllIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat).setPriority(Notification.PRIORITY_MIN)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.notification_unhide_summary)).setLocalOnly(true)
            //.addAction(R.drawable.ic_action_eye_open_dark, getString(R.string.notification_action_unhide), unhidePendingIntent)
            //.addAction(R.drawable.ic_action_cancel_dark, getString(R.string.notification_action_close_all), closeAllPendingIntent)
            .addAction(/*from   w  ww.  ja  va 2  s  . c o  m*/
                    Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ? R.drawable.ic_action_cancel_white
                            : R.drawable.ic_action_cancel_dark,
                    getString(R.string.notification_action_close_all), closeAllPendingIntent)
            .setContentIntent(unhidePendingIntent);

    /*MainController controller = MainController.get();
    if (null != controller && null != controller.mBubbleFlowDraggable) {
    if (!controller.mBubbleFlowDraggable.isExpanded()) {
        notificationBuilder
                .addAction(R.drawable.ic_stat, getString(R.string.notification_expand), showContentViewPendingIntent)
                .setContentText(getString(R.string.notification_unhide_expand_summary));
    }
    }*/

    NotificationManagerCompat.from(this).cancelAll();
    startForeground(1, notificationBuilder.build());
    //Log.d("blerg", "showUnhideHiddenNotification()");
}

From source file:com.android.inputmethod.latin.settings.CustomInputStyleSettingsFragment.java

private AlertDialog createDialog() {
    final String imeId = mRichImm.getInputMethodIdOfThisIme();
    final AlertDialog.Builder builder = new AlertDialog.Builder(
            DialogUtils.getPlatformDialogThemeContext(getActivity()));
    builder.setTitle(R.string.custom_input_styles_title).setMessage(R.string.custom_input_style_note_message)
            .setNegativeButton(R.string.not_now, null)
            .setPositiveButton(R.string.enable, new DialogInterface.OnClickListener() {
                @Override/* w  w w.  j  av  a 2  s  . c  o m*/
                public void onClick(DialogInterface dialog, int which) {
                    final Intent intent = IntentUtils.getInputLanguageSelectionIntent(imeId,
                            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    // TODO: Add newly adding subtype to extra value of the intent as a hint
                    // for the input language selection activity.
                    // intent.putExtra("newlyAddedSubtype", subtypePref.getSubtype());
                    startActivity(intent);
                }
            });

    return builder.create();
}

From source file:com.iped.ipcam.bitmapfun.ImageGrid.java

private void loadImageFiles() {
    if (Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
        String sdDir = Environment.getExternalStorageDirectory().getAbsolutePath();// 
        File file = new File(sdDir + FileUtil.parentPath + FileUtil.picForder);
        if (!file.exists()) {
            file.mkdirs();/*from  ww  w .  j a va 2s .  co  m*/
            File noMedia = new File(sdDir + FileUtil.parentPath + FileUtil.picForder + ".nomedia");
            try {
                noMedia.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        String fileThumbnail = sdDir + FileUtil.parentPath + FileUtil.picThumbnail;
        File thumbnailFile = new File(fileThumbnail);
        if (!thumbnailFile.exists()) {
            thumbnailFile.mkdirs();
            File noMedia = new File(sdDir + FileUtil.parentPath + FileUtil.picThumbnail + ".nomedia");
            try {
                noMedia.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        File[] files = file.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                if (pathname.isDirectory()) {
                    return true;
                }
                String name = pathname.getName().toLowerCase();
                return name.endsWith(".jpeg") || name.endsWith(".jpg") || name.endsWith(".png")
                        || name.endsWith(".gif");
            }
        });
        for (int i = 0; i < files.length; i++) {
            if (files[i].isFile()) {
                //paths[i] = files[i].getPath();
                ImageInfo imageInfo = new ImageInfo();
                imageInfo.path = files[i].getPath();
                imageInfo.title = files[i].getName();
                imageInfo.thumbnail = fileThumbnail + imageInfo.title;
                System.out.println(imageInfo.thumbnail + "  " + imageInfo.title);
                File thumbnail = new File(imageInfo.thumbnail);
                if (!thumbnail.exists()) {
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inJustDecodeBounds = true;
                    Bitmap bitmap = BitmapFactory.decodeFile(imageInfo.path, options); //bm
                    options.inJustDecodeBounds = false;
                    int be = (int) (options.outWidth / (float) columnWidth);
                    if (be <= 0)
                        be = 1;
                    options.inSampleSize = be;
                    bitmap = BitmapFactory.decodeFile(imageInfo.path, options);
                    FileOutputStream out = null;
                    try {
                        out = new FileOutputStream(thumbnail);
                        if (bitmap != null && bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out)) {
                            out.flush();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        if (out != null) {
                            try {
                                out.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }

                }
                Uri uri = Uri.parse("file://" + files[i].getPath());
                imageInfo.setActivity(uri,
                        Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                imageList.add(imageInfo);
                handler.sendEmptyMessage(1);
            }
        }
    }
}