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 void openAppDetailSetting(Context context, String packageName) {
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri uri = Uri.fromParts("package", packageName, null);
    intent.setData(uri);//from  w  w w  .j  a  va 2 s .co  m
    context.startActivity(intent);
}

From source file:Main.java

public static void launchApplication(Context context, String pkgname) {
    Intent intent = context.getPackageManager().getLaunchIntentForPackage(pkgname);
    intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);

    context.startActivity(intent);/*  w w  w  . j  av a 2s .c o m*/
}

From source file:Main.java

public static void shareToGMail(Context context, String[] email, String subject, String content) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, content);
    final PackageManager pm = context.getPackageManager();
    final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
    ResolveInfo best = null;//from  w  ww . j a  v a2s .  co  m
    for (final ResolveInfo info : matches)
        if (info.activityInfo.packageName.endsWith(".gm")
                || info.activityInfo.name.toLowerCase().contains("gmail"))
            best = info;
    if (best != null)
        emailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
    context.startActivity(emailIntent);
}

From source file:Main.java

public static void startActivityForResult(Activity context, Class<?> cls, String data, int flag) {
    Intent intent = new Intent(context, cls);
    intent.putExtra("data", data);
    intent.setFlags(flag);
    context.startActivityForResult(intent, flag);
}

From source file:Main.java

public static void startActivityForResult(Activity activity, Class<?> cls, String data, int flag) {
    Intent intent = new Intent(activity, cls);
    intent.putExtra("data", data);
    intent.setFlags(flag);
    activity.startActivityForResult(intent, flag);
}

From source file:Main.java

private static void uninstallAppByClick(Context context, String pkgName) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_DELETE);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.parse("package:" + pkgName));
    context.startActivity(intent);/* w ww .  ja v a  2  s .  c om*/
}

From source file:Main.java

public static void sair(Intent intent, Context context) {
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);//from   w ww  .ja v  a2 s.c o m
}

From source file:Main.java

static void resolveIntent(Intent intent, Context context) {
    if (context instanceof Application) {
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    }/*from   w  w w.  j  av a  2  s.  c o  m*/
    context.startActivity(intent);
}

From source file:Main.java

public static void install(Context context, String fileName) {
    if (TextUtils.isEmpty(fileName) || context == null) {
        return;//from ww w . jav a  2s.  c o  m
    }
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction(android.content.Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
        context.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * When adding account/* w  w  w .ja v a 2 s  .  c  om*/
 * open the same UI screen for user to choose account
 */
public static Intent getIntentForAddingAccount() {
    final Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[] { ContactsContract.AUTHORITY });
    return intent;
}