Example usage for android.content Intent setFlags

List of usage examples for android.content Intent setFlags

Introduction

In this page you can find the example usage for android.content Intent setFlags.

Prototype

public @NonNull Intent setFlags(@Flags int flags) 

Source Link

Document

Set special flags controlling how this intent is handled.

Usage

From source file:Main.java

public static void makeingCalls(Context context, String phoneNum) {
    if (TextUtils.isEmpty(phoneNum)) {
        return;/*from   ww w  . j  a  v  a  2 s  . co m*/
    }
    Intent phoneIntent = new Intent("android.intent.action.CALL", Uri.parse("tel:" + phoneNum));
    phoneIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(phoneIntent);
}

From source file:com.manning.androidhacks.hack046.helper.NotificationHelper.java

private static PendingIntent getReplyPendingIntent(Context ctx) {
    Intent intent = new Intent(ctx, ReplyActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    return PendingIntent.getActivity(ctx, 0, intent, 0);
}

From source file:Main.java

/**
 * "Exits" the app to the Home screen".//w  w w.  j a  v  a 2 s  .c  o  m
 * @param context Application context
 */
public static void exitToHome(final Context context) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:Main.java

public static void chooseHomeApp(Context context) {
    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(startMain);/*from   w w  w.  j  a v a2  s  .c  om*/
}

From source file:Main.java

public static void callSysShare(Context context, String chooserTitle, String shareTitle, String shareText,
        String mime, Uri uri) {//w w  w .ja v  a 2  s  .  co  m
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Intent.EXTRA_TEXT, shareText);
    intent.putExtra(Intent.EXTRA_SUBJECT, shareTitle);
    intent.setType(mime);
    if (uri != null) {
        intent.putExtra(Intent.EXTRA_STREAM, uri);
    }
    context.startActivity(Intent.createChooser(intent, chooserTitle));
}

From source file:Main.java

public static void sendMessage(Context activity, String phoneNumber, String smsContent) {
    if (phoneNumber == null || phoneNumber.length() < 4) {
        return;//  w  w w. j  a  va  2s  . c om
    }
    Uri uri = Uri.parse("smsto:" + phoneNumber);
    Intent it = new Intent(Intent.ACTION_SENDTO, uri);
    it.putExtra("sms_body", smsContent);
    it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    activity.startActivity(it);
}

From source file:Main.java

public static void startBrowser(Context context, String url) {
    try {/*from ww  w.  j ava2 s .c o  m*/
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri content_url = Uri.parse(url);
        intent.setData(content_url);
        context.startActivity(intent);
    } catch (Exception e) {

    }
}

From source file:Main.java

public static void startAppByPackageName(Context context, String packageName) {
    PackageInfo pi = null;//from   w w  w  .ja va 2 s .  c  om
    try {
        pi = context.getPackageManager().getPackageInfo(packageName, 0);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resolveIntent.setPackage(pi.packageName);

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

    ResolveInfo ri = apps.iterator().next();
    if (ri != null) {
        String packageName1 = ri.activityInfo.packageName;
        String className = ri.activityInfo.name;

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        ComponentName cn = new ComponentName(packageName1, className);

        intent.setComponent(cn);
        context.startActivity(intent);
    }

}

From source file:Main.java

/**
 * Minimizes the app/*from   ww  w  . jav  a  2 s.  c  om*/
 * @param context the context
 */
public static void minimizeApp(Context context) {
    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(startMain);
}

From source file:Main.java

public static void openView(Context context, String url) {
    try {//ww w  .ja  va 2 s . c  o m
        Intent intentUri = new Intent(Intent.ACTION_VIEW);
        intentUri.setData(Uri.parse(url));
        intentUri.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intentUri);
    } catch (Exception e) {
    }
}