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 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 goHome(Context context) {
    Intent mHomeIntent = new Intent(Intent.ACTION_MAIN);
    mHomeIntent.addCategory(Intent.CATEGORY_HOME);
    mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    context.startActivity(mHomeIntent);//from   w w w  . j a v  a 2s  . c  o  m
}

From source file:Main.java

public static void restartActivity(Activity activity) {

    if (activity == null)
        return;/*ww w. ja va2  s. c  om*/

    if (Build.VERSION.SDK_INT >= 11) {
        activity.recreate();
    } else {
        Intent intent;
        intent = activity.getIntent();
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.finish();
        activity.overridePendingTransition(0, 0);
        activity.startActivity(intent);
        activity.overridePendingTransition(0, 0);
    }

}

From source file:Main.java

public static void gotoDeskTop(AccessibilityService service) {
    try {//  ww  w.j a  va  2  s .c  o  m
        Intent home = new Intent(Intent.ACTION_MAIN);
        home.addCategory(Intent.CATEGORY_HOME);
        home.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        service.getApplicationContext().startActivity(home);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * start home intent/*from  ww w  .j ava  2 s.c  o  m*/
 *
 * @param context
 */
public static void startHomeActivity(Context context) {
    Intent homeIntent = new Intent(Intent.ACTION_MAIN);
    homeIntent.addCategory(Intent.CATEGORY_HOME);
    homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    context.startActivity(homeIntent);
}

From source file:Main.java

/**
 * Restart the app./*from   w  w  w .  j  av  a2s .  c om*/
 * @param context
 */
public static void restartApplication(Context context) {
    Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent p = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 500, p);

    //kill the application
    System.exit(0);
}

From source file:Main.java

/**
 * @param artistName//  w ww  .j av  a2 s .c om
 */
public static void shopFor(Context mContext, String artistName) {
    String str = "https://market.android.com/search?q=%s&c=music&featured=MUSIC_STORE_SEARCH";
    Intent shopIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(str, Uri.encode(artistName))));
    shopIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shopIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    mContext.startActivity(shopIntent);
}

From source file:Main.java

private static void prepareRestartAppIntent(Intent i) {
    i.setAction(Intent.ACTION_MAIN);//from w ww  .  ja  v  a 2 s  .c  o m
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}

From source file:Main.java

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

From source file:Main.java

/**
 * @param packageName/*from   www.ja va2  s .c om*/
 * @param context
 */
public static void openApp(String packageName, Context context) {

    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);

    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    resolveIntent.setPackage(packageName);

    List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(resolveIntent, 0);

    ResolveInfo ri = apps.iterator().next();

    if (ri != null) {

        String packageName_i = ri.activityInfo.packageName;

        String className_i = ri.activityInfo.name;

        Intent intent = new Intent(Intent.ACTION_MAIN);

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        ComponentName cn = new ComponentName(packageName_i, className_i);

        intent.setComponent(cn);

        context.startActivity(intent);

    }

}