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 final void install(Context context, String path) {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.parse("file://" + path), "application/vnd.android.package-archive");
    context.startActivity(intent);// www  . jav a 2 s .  c  o m
}

From source file:Main.java

public static void launchApp(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    Intent intent = pm.getLaunchIntentForPackage(packageName);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);/*from   w  ww  .j  a va2  s .co m*/
}

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(//from   w w w  .java  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 downloadApkFromBrower(Context context, String url) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    Uri content_url = Uri.parse(url);//from   ww w .j  a va 2 s.  co  m
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(content_url);
    context.startActivity(intent);
}

From source file:Main.java

public static Intent getSendSmsIntent(String phoneNumber, String content) {
    Uri uri = Uri.parse("smsto:" + phoneNumber);
    Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
    intent.putExtra("sms_body", content);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}

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

From source file:Main.java

public static void startActivity(Context context, Intent intent) {
    if (context == null || intent == null) {
        return;//from   w w w  .j av  a  2  s .co m
    }

    if (!(context instanceof Activity)) {
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }

    try {
        context.startActivity(intent);
    } catch (Exception e) {

    }
}

From source file:Main.java

public static void openPDF(Context context, String path) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri uri = Uri.fromFile(new File(path));
    intent.setDataAndType(uri, "application/pdf");
    try {//from  www . java 2s  . co m
        context.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void startSearchPlayApplication(Context mContext, String pkgName) {
    try {/*from  w  w  w.j  a va  2  s . c o  m*/
        Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkgName));
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(mIntent);
    } catch (android.content.ActivityNotFoundException anfe) {
        Intent mIntent1 = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/details?id=" + pkgName));
        mIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(mIntent1);
    }
}

From source file:Main.java

public static void uninstallApk(Context ctx, String packageName) {
    Uri packageURI = Uri.parse("package:" + packageName);
    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
    uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ctx.startActivity(uninstallIntent);/*w  w w .  j ava 2s.  c  o m*/
}