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

/**
 * Restart the Activity//w w w. j ava2s . c  o m
 *
 * @param activity
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void restartActivity(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activity.recreate();
    } else {
        Intent intent = activity.getIntent();
        activity.overridePendingTransition(0, 0);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        activity.finish();

        activity.overridePendingTransition(0, 0);
        activity.startActivity(intent);
    }
}

From source file:Main.java

static void showDesktop(Context ctx) {
    Intent mHomeIntent;
    mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
    mHomeIntent.addCategory(Intent.CATEGORY_HOME);
    mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    ctx.startActivity(mHomeIntent);/*from  www .ja v  a2 s  .c o m*/
}

From source file:Main.java

/**
 * Tries to open the app store by using the passed storeAppUri. If this
 * fails, opens the store website./*  w ww  . j  a v  a2s .c o m*/
 *
 * @param ctx             The Android context.
 * @param storeAppUri     The app store uri.
 * @param storeWebsiteUri The store website.
 */
public static void openAppStore(Context ctx, Uri storeAppUri, Uri storeWebsiteUri) {
    Intent marketIntent;

    try {
        marketIntent = new Intent(Intent.ACTION_VIEW, storeAppUri);
        marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        ctx.startActivity(marketIntent);

    } catch (android.content.ActivityNotFoundException anfe) {
        marketIntent = new Intent(Intent.ACTION_VIEW, storeWebsiteUri);
        marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        ctx.startActivity(marketIntent);
    }
}

From source file:Main.java

public static Intent getOpenFileIntent(Uri uri, String mimeType) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, mimeType);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    return intent;
}

From source file:Main.java

public static void openImage(Context mContext, String imagePath) {
    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(imagePath));
    intent.setDataAndType(uri, "image/*");
    mContext.startActivity(intent);//from  www . j  av  a 2s  .  com
}

From source file:Main.java

/**
 * Used to search the Play Store for a specific app.
 * /*w  w  w . j  ava2  s .co  m*/
 * @param context The {@link Context} to use.
 * @param themeName The theme name to search for.
 */
public static void openAppPage(final Context context, final String themeName) {
    final Intent shopIntent = new Intent(Intent.ACTION_VIEW);
    shopIntent.setData(Uri.parse(APP_URI + themeName));
    shopIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shopIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(shopIntent);
}

From source file:Main.java

public static Intent getAppDetailsSettingsIntent(String packageName) {
    Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
    intent.setData(Uri.parse("package:" + packageName));
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}

From source file:Main.java

public static Intent getWordFileIntent(String param) {

    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(param));

    intent.setDataAndType(uri, "application/msword");

    return intent;

}

From source file:Main.java

public static void install(Context context, File file) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);/*  ww w.  j a va2 s.  c om*/
}

From source file:Main.java

public static boolean gotoAccessibilitySettings(Context context) {
    Intent settingsIntent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
    if (!(context instanceof Activity)) {
        settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }//from w w w. j  a va2  s  .  c  o  m
    boolean isOk = true;
    try {
        context.startActivity(settingsIntent);
    } catch (ActivityNotFoundException e) {
        isOk = false;
    }
    return isOk;
}