Example usage for android.content Intent FLAG_ACTIVITY_NEW_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_NEW_TASK

Introduction

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

Prototype

int FLAG_ACTIVITY_NEW_TASK

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

Click Source Link

Document

If set, this activity will become the start of a new task on this history stack.

Usage

From source file:Main.java

public static boolean installApk(Context context, String filePath) {
    File file = new File(filePath);
    if (!file.exists() || !file.isFile() || file.length() <= 0) {
        return false;
    }//  w  ww .  j a va  2s.  com
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
    return true;
}

From source file:Main.java

/**
 * Install apk//from  www  .  j  av  a2  s .  co  m
 */
public static void installApk(Context context, File file) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

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);//from  w  ww.j a v a 2  s .c  om
}

From source file:Main.java

/**
 * install an apk bu apkPath/*from  w  ww .j av  a 2  s  .  c o m*/
 *
 * @param context Context
 * @param apkPath apkPath
 */
public static final void installApk(Context context, String apkPath) {
    if (TextUtils.isEmpty(apkPath)) {
        return;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(new File(apkPath)), "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static void install(Context context, String apkFilePath) {
    if (context == null) {
        throw new RuntimeException("ApkUtils install apk method and parameter context  == null?");
    }// w w  w  . j av a 2s. co  m

    File file = new File(apkFilePath);

    if (!file.exists()) {
        return;
    }

    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static boolean installNormal(Context context, String filePath) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    File file = new File(filePath);
    if (file == null || !file.exists() || !file.isFile() || file.length() <= 0) {
        return false;
    } else {/*  www . ja  v a 2 s  .  c o m*/
        intent.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
        return true;
    }
}

From source file:Main.java

/**
 * <pre>//  w  w  w .  j a va2 s . c  o  m
 * Start other app by its package name.
 * </pre>
 * @param packageName app 's package name
 */
public static void openApp(String packageName) {
    Context context = getCurrentContext();
    PackageManager manager = context.getPackageManager();
    Intent intent = manager.getLaunchIntentForPackage(packageName);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    context.startActivity(intent);
}

From source file:Main.java

public static void installApk(Context context, File file) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setType("application/vnd.android.package-archive");
    intent.setData(Uri.fromFile(file));//from w  w  w. j a v a2 s .  c o  m
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

}

From source file:Main.java

public static void send(Context context, String path) {

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    PackageManager pm = context.getPackageManager();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
    List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    boolean flag = false;
    for (ResolveInfo info : list) {
        if (info.activityInfo.packageName.toLowerCase().contains("bluetooth")
                || info.activityInfo.name.toLowerCase().contains("bluetooth")) {
            ApplicationInfo appInfo = null;
            try {
                appInfo = pm.getApplicationInfo(info.activityInfo.packageName, PackageManager.GET_META_DATA);
            } catch (PackageManager.NameNotFoundException e) {

            }/*from   w  ww  . j  a v a2s. c  o  m*/
            if (appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0
                    && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
                flag = true;
                break;
            }
        }
    }
    if (!flag) {
        return;
    }
    context.startActivity(intent);
}

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);/*from  w w  w  . j a  va  2  s.  c  om*/
    } else {
        Log.e(TAG, "Intent is not available!");
    }
}