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:Main.java

public static Intent getInputLanguageSelectionIntent(String inputMethodId, int flagsForSubtypeSettings) {
    // Refer to android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS
    final String action = INPUT_METHOD_SUBTYPE_SETTINGS;
    final Intent intent = new Intent(action);
    if (!TextUtils.isEmpty(inputMethodId)) {
        intent.putExtra(EXTRA_INPUT_METHOD_ID, inputMethodId);
    }//from   w  w  w  .ja  v  a2  s.c  o  m
    if (flagsForSubtypeSettings > 0) {
        intent.setFlags(flagsForSubtypeSettings);
    }
    return intent;
}

From source file:Main.java

@SuppressLint("NewApi")
public static void sendSchemeForResult(Fragment activity, String url, int requestCode, Bundle bundle,
        int flag) {
    Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
    if (bundle != null) {
        intent.putExtras(bundle);//from  w ww  .  j a v  a 2s .c  o  m
    }

    if (flag != 0) {
        intent.setFlags(flag);
    }

    activity.startActivityForResult(intent, requestCode);
}

From source file:Main.java

public static void startInstall(final Context context, String fileName) {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + getSdcardFileName(fileName)),
            "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);/* ww  w  .j  a  v  a 2  s . c om*/
}

From source file:com.doplgangr.secrecy.Util.java

public static void openURI(String uri) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(uri));//from  w  w  w.  jav a2  s . c  o  m
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    CustomApp.context.startActivity(i);

}

From source file:Main.java

public static void actionStart(Activity activity, Class cls, Bundle bundle, int... intentFlags) {
    Intent intent = new Intent(activity, cls);
    if (intentFlags != null) {
        for (int i = 0; i < intentFlags.length; i++) {
            if (intentFlags[i] != 0) {
                if (i == 0) {
                    intent.setFlags(intentFlags[i]);
                } else {
                    intent.addFlags(intentFlags[i]);
                }/* w  w  w .  jav a  2 s  .  c o m*/
            }
        }
    }
    if (bundle != null) {
        intent.putExtras(bundle);
    }
    activity.startActivity(intent);
}

From source file:Main.java

/**
 * Open an URL in a message.//ww  w. j av  a  2s.com
 *
 * This is intended to mirror the operation of the original
 * (see android.webkit.CallbackProxy) with one addition of intent flags
 * "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET".  This improves behavior when sublaunching
 * other apps via embedded URI's.
 *
 * We also use this hook to catch "mailto:" links and handle them locally.
 *
 * @param activity parent activity
 * @param url URL to open
 * @param senderAccountId if the URL is mailto:, we use this account as the sender.
 *        TODO When MessageCompose implements the account selector, this won't be necessary.
 *        Pass {@link Account#NO_ACCOUNT} to use the default account.
 * @return true if the URI has successfully been opened.
 */
public static boolean openUrlInMessage(Activity activity, String url, long senderAccountId) {
    // hijack mailto: uri's and handle locally
    //***
    //if (url != null && url.toLowerCase().startsWith("mailto:")) {
    //    return MessageCompose.actionCompose(activity, url, senderAccountId);
    //}

    // Handle most uri's via intent launch
    boolean result = false;
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    try {
        activity.startActivity(intent);
        result = true;
    } catch (ActivityNotFoundException ex) {
        // No applications can handle it.  Ignore.
    }
    return result;
}

From source file:Main.java

public static Intent getLaunchIntent(Context context, String title, String url, String sel) {
    Intent intent = null;
    String number = parseTelephoneNumber(sel);
    if (number != null) {
        intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + number));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {/*from w w  w  .  j  a va 2  s. co m*/
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (isMapsURL(url)) {
            intent.setClassName(GMM_PACKAGE_NAME, GMM_CLASS_NAME);
        } else if (isYouTubeURL(url)) {
            intent.setPackage(YT_PACKAGE_NAME);
        }

        // Fall back if we can't resolve intent (i.e. app missing)
        PackageManager pm = context.getPackageManager();
        if (null == intent.resolveActivity(pm)) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
    }

    if (sel != null && sel.length() > 0) {
        ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setText(sel);
    }

    return intent;
}

From source file:com.cbtec.eliademy.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from   w  w  w  . jav a2  s.  c o  m*/

private static void generateNotification(Context context, String message) {
    int icon = R.drawable.icon;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, Eliademy.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:com.github.fi3te.iliasdownloader.controller.Util.java

public static void openFile(File file, Activity forMessages) {
    if (file != null && forMessages != null && file.isFile()) {
        String extension = FilenameUtils.getExtension(file.getPath());
        if (extension.length() > 0) {
            try {
                extension = extension.toLowerCase();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(file),
                        MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                forMessages.startActivity(intent);
            } catch (ActivityNotFoundException anfe) {
                Toast.makeText(forMessages, forMessages.getResources().getString(R.string.unknown_type),
                        Toast.LENGTH_SHORT).show();
            }/*from   w  ww  .  jav  a 2  s  .  co m*/
        }
    }
}

From source file:Main.java

public static void goToMiuiPermissionActivity_V7(Context context) {
    Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
    intent.setClassName("com.miui.securitycenter",
            "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
    intent.putExtra("extra_pkgname", context.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (isIntentAvailable(intent, context)) {
        context.startActivity(intent);/*  w  ww .  j av  a 2 s. com*/
    } else {
        Log.e(TAG, "Intent is not available!");
    }
}