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 Intent getOpenFileIntent(File file) {
    if (file == null || !file.exists() || !file.isFile()) {
        return null;
    }//from  w  w w  . j a v a 2  s .c  om
    String extension = MimeTypeMap.getFileExtensionFromUrl(file.getAbsolutePath());
    String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    if (extension == null || mimeType == null) {
        return null;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(file), mimeType);
    return intent;
}

From source file:Main.java

/**
 * Install apk//from  w  w  w .  j av a2 s. c  om
 */
public static void installApk(Context context, Uri file) {
    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

private static void showAppInMarket(Context context, String desiredPackageName) {
    String url = "";

    try {//w  w  w.j ava2  s. c o m
        //Check whether Google Play store is installed or not:
        context.getPackageManager().getPackageInfo("com.android.vending", 0);
        url = "market://details?id=" + desiredPackageName;
    } catch (final Exception e) {
        url = "https://play.google.com/store/apps/details?id=" + desiredPackageName;
    }

    //Open the app page in Google Play store:
    final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:Main.java

public static void chooserSysPics(Context context, int requestCode) {
    if (context == null) {
        return;//from  w  w w  . j  av a  2s . c  o  m
    }

    try {
        Intent localIntent = new Intent();
        localIntent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        localIntent.setType("image/*");
        // Intent.ACTION_GET_CONTENT
        localIntent.setAction("android.intent.action.GET_CONTENT");
        if (context instanceof Activity) {
            ((Activity) context).startActivityForResult(localIntent, requestCode);
        } else {
            localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(localIntent);
        }
    } catch (Exception e) {
    }
}

From source file:Main.java

public static Intent getLaunchIntent(Context context, String title, String url, String sel) {
    Intent intent = null;/*from ww w .  ja  v a 2s .  c o  m*/
    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 {
        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:Main.java

public static void chooserPics(Context context, int requestCode) {
    if (context == null) {
        return;/* w  w w.  j a v  a 2 s.c o m*/
    }

    try {
        Intent localIntent = new Intent();
        localIntent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        localIntent.setType("image/*");
        localIntent.setAction(Intent.ACTION_GET_CONTENT);
        if (context instanceof Activity) {
            ((Activity) context).startActivityForResult(Intent.createChooser(localIntent, "Select Picture"),
                    requestCode);
        } else {
            localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(Intent.createChooser(localIntent, "Select Picture"));
        }
    } catch (Exception e) {
    }
}

From source file:Main.java

public static void installApk(Context context, Uri file) {
    if (context == null)
        return;//w  w w . j av a2s  .  c  o  m
    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 startNewActivity(Context context, Class<?> clazz) {
    Intent intent = new Intent(context, clazz);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);//from  w  w w  . j  a v a 2  s. co m
}

From source file:Main.java

public static void installApk(Context context, File file) {
    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);// w  w  w.j  a v a  2 s  .  com
}

From source file:Main.java

public static void goProgram(Context context, String pkg, String fullclasspath) {
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(new ComponentName(pkg, fullclasspath));
    context.startActivity(intent);// w w  w . j a  v a 2 s.  c  o m
}