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 startActivity(Context context, Class<?> clazz) {
    Intent intent = new Intent(context, clazz);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    context.startActivity(intent);/*from w  w w .ja v  a  2 s .  co  m*/
}

From source file:Main.java

public static void openURL(Context ctx, String url) {
    Intent i2 = new Intent(Intent.ACTION_VIEW);
    i2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i2.setData(Uri.parse(url));/*from   ww  w . java  2s  .c  om*/
    ctx.startActivity(i2);
}

From source file:Main.java

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

From source file:Main.java

public static void startActivityWithNewTask(@NonNull Context context, @NonNull Class className) {
    Intent intent = new Intent(context, className);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(intent);/*from   w  w w.j a va 2  s  .c  o m*/
}

From source file:Main.java

public static void installApk(Context context, File filename) {
    Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.fromFile(filename));
    context.startActivity(intent);/*from   ww w .ja  v a 2  s.  c  o  m*/
}

From source file:Main.java

public static Intent getVideoFileIntent(String param) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("oneshot", 0);
    intent.putExtra("configchange", 0);
    Uri uri = Uri.fromFile(new File(param));
    intent.setDataAndType(uri, "video/*");
    return intent;
}

From source file:Main.java

public static Intent getAudioFileIntent(String param) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("oneshot", 0);
    intent.putExtra("configchange", 0);
    Uri uri = Uri.fromFile(new File(param));
    intent.setDataAndType(uri, "audio/*");
    return intent;
}

From source file:Main.java

public static void installApk(Context context, String fileName) {
    if (fileName != null && fileName.contains(".apk")) {
        //         File f = new File(fileName);
        //         if(f.exists()){
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setDataAndType(Uri.parse("file://" + fileName), "application/vnd.android.package-archive");
        context.startActivity(intent);/*  w  w w. j a  va2  s  . c  o m*/
        //         }
    }
}

From source file:Main.java

private static Intent getAudioFileIntent(File file) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("oneshot", 0);
    intent.putExtra("configchange", 0);
    Uri uri = Uri.fromFile(file);/*  www.  j  a va  2s.c om*/
    intent.setDataAndType(uri, "audio/*");
    return intent;
}

From source file:Main.java

private static Intent getVideoFileIntent(File file) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("oneshot", 0);
    intent.putExtra("configchange", 0);
    Uri uri = Uri.fromFile(file);//from  ww w  .  j a  v a 2 s .  c  o  m
    intent.setDataAndType(uri, "video/*");
    return intent;
}