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 goToMiuiPermissionActivity_V8(Context context) {
    Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
    intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
    //        intent.setPackage("com.miui.securitycenter");
    intent.putExtra("extra_pkgname", context.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (isIntentAvailable(intent, context)) {
        context.startActivity(intent);//www  . ja  va  2  s  .  c o m
    } else {
        intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
        intent.setPackage("com.miui.securitycenter");
        intent.putExtra("extra_pkgname", context.getPackageName());
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        if (isIntentAvailable(intent, context)) {
            context.startActivity(intent);
        } else {
            Log.e(TAG, "Intent is not available!");
        }
    }
}

From source file:com.google.android.gcm.demo.app.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 */// w w  w.j a  v a 2s.  co m
private static void generateNotification(Context context, String message, String data) {
    int icon = R.drawable.ic_stat_gcm;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(0);

    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, DemoActivity.class);
    notificationIntent.putExtra(CommonUtilities.EXTRA_TEAM_IN_JSON, data);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:Main.java

public static void installApk(Context context, File file) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setType("application/vnd.android.package-archive");
    intent.setData(Uri.fromFile(file));//w  w w.  j a v a 2  s . com
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

}

From source file:com.rocketsingh.biker.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 */// w  ww. jav  a 2 s . co  m
public static void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MapActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();

}

From source file:com.bourke.kitchentimer.utils.Utils.java

public static void donate(Context mContext) {
    Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("market://search?q=Donation%20pub:%22Roberto%20Leinardi%22"));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mContext.startActivity(intent);/* w  ww.  j  a va 2s .co  m*/
}

From source file:Main.java

public static void installApk(Context context, File apkfile) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setType("application/vnd.android.package-archive");
    intent.setData(Uri.fromFile(apkfile));
    intent.setDataAndType(Uri.fromFile(apkfile), "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);//from   ww  w  .j a  v a  2s. c  o m
}

From source file:Main.java

public static Intent getSmsIntent() {
    Intent conversations = new Intent(Intent.ACTION_MAIN);
    //conversations.addCategory(Intent.CATEGORY_DEFAULT);
    conversations.setType(SMS_MIME_TYPE);
    // should I be using FLAG_ACTIVITY_RESET_TASK_IF_NEEDED??
    int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TOP;
    conversations.setFlags(flags);

    return conversations;
}

From source file:com.adguard.android.commons.BrowserUtils.java

public static void openSamsungBlockingOptions(Context context) {
    Intent intent = new Intent();
    intent.setAction(SAMSUNG_CONTENT_BLOCKER_ACTION);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {
        boolean found = false;
        for (ResolveInfo info : list) {
            if (info.activityInfo.packageName.contains(SAMSUNG_PACKAGE_PREFIX)
                    || info.activityInfo.packageName.contains(SAMSUNG)) {
                found = true;//w w w. ja va2 s. com
                intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
            }
        }
        if (found) {
            context.startActivity(intent);
        }
    }
}

From source file:com.adguard.android.commons.BrowserUtils.java

public static void openYandexBlockingOptions(Context context) {
    Intent intent = new Intent();
    intent.setAction(YANDEX_CONTENT_BLOCKER_ACTION);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {
        context.startActivity(intent);/*from   w ww . j a va 2  s  .  c  om*/
        return;
    }

    // For samsung-type action in Yandex browser
    intent.setAction(SAMSUNG_CONTENT_BLOCKER_ACTION);
    list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {

        ComponentName componentName = getYandexBrowser(context, SAMSUNG_CONTENT_BLOCKER_ACTION);
        if (componentName != null) {
            intent.setClassName(componentName.getPackageName(), componentName.getClassName());
        }

        context.startActivity(intent);
    }
}

From source file:com.arisprung.tailgate.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*  w  w  w. j  ava  2  s  .c o m*/
private static void generateNotification(Context context, MessageBean message) {
    //      Intent notificationIntent = new Intent(ctx, MainActivity.class);
    //      PendingIntent contentIntent = PendingIntent.getActivity(ctx,
    //              10, notificationIntent,
    //              PendingIntent.FLAG_CANCEL_CURRENT);
    //
    //      NotificationManager nm = (NotificationManager) ctx
    //              .getSystemService(Context.NOTIFICATION_SERVICE);
    //
    //      Resources res = ctx.getResources();
    //      Notification.Builder builder = new Notification.Builder(ctx);
    //      
    //      Bitmap profile = TailGateUtility.getUserPic(message.getFaceID());
    //
    //      builder.setContentIntent(contentIntent)
    //                  .setSmallIcon(R.drawable.ic_launcher)
    //                  .setLargeIcon(profile)
    //                  .setTicker(res.getString(R.string.app_name))
    //                  .setWhen(System.currentTimeMillis())
    //                  .setAutoCancel(true)
    //                  .setContentTitle(message.getUserName())
    //                  .setContentText(message.getMessage());
    //      Notification n = builder.build();
    //
    //      nm.notify(0, n);
    int icon = R.drawable.fanatic_icon_72px;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message.getMessage(), when);

    String name = message.getUserName();
    Intent notificationIntent = new Intent(context, MainActivity.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, name, message.getMessage(), intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);

}