Example usage for android.content Intent addFlags

List of usage examples for android.content Intent addFlags

Introduction

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

Prototype

public @NonNull Intent addFlags(@Flags int flags) 

Source Link

Document

Add additional flags to the intent (or with existing flags value).

Usage

From source file:Main.java

public static void uninstallApk(Context context, String packageName) {
    Intent intent = new Intent(Intent.ACTION_DELETE);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri packageURI = Uri.parse("package:" + packageName);
    intent.setData(packageURI);/* w ww.j  a v a2  s  . c o  m*/
    context.startActivity(intent);
}

From source file:Main.java

public static void installApkFromLocalPath(Activity activity, String apkname) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(// w  ww  . j  a va  2  s . c o m
            Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/ewgvip/" + apkname),
            "application/vnd.android.package-archive");
    activity.startActivity(intent);
}

From source file:Main.java

public static void installApk(Context context, File file) {
    if (context == null)
        return;//  w  w  w  . j  a v a  2 s .  co m
    if (file == null)
        return;
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    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 void installApk(Context context, Uri file) {
    if (context == null)
        return;//from   w  ww  .j  av  a  2  s .com
    if (file == null)
        return;
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(file, "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static void launchAppMarket(Context context, String pkgname) {
    Uri uri = Uri.parse("market://details?id=" + pkgname);
    // uri = Uri.parse("market://details?id=" + "com.tencent.mobileqq");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);/*from   ww  w  .j  av a2  s .c o  m*/
}

From source file:Main.java

public static void installApk(Context context, File file) {
    if (!file.exists()) {
        return;//  w  w  w . j ava 2s .c o m
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

public static void installApk(Context context, String filePath) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive");
    context.startActivity(intent);//from w  w w  .j  av a2  s.  c om
}

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?");
    }/*from   w w  w .  j a  v  a2s . c o  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 void startActivity(Context context, Class cls, int intentflag) {
    Intent intent = new Intent(context, cls);
    intent.addFlags(intentflag);
    context.startActivity(intent);/*from   w w  w  . j av a 2  s  . c o m*/
}

From source file:Main.java

public static void startNewActivity(Context context, Class<?> clazz) {
    Intent intent = new Intent(context, clazz);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);/*w  w  w .j  a  va 2  s  .  co m*/
}