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

private static Intent getComponentIntent(String packageName, String className, Bundle bundle) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    if (bundle != null)
        intent.putExtras(bundle);/*  w w w . j av  a2s . com*/
    ComponentName cn = new ComponentName(packageName, className);
    intent.setComponent(cn);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}

From source file:Main.java

public static Intent getComponentIntent(String packageName, String className, Bundle bundle) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    if (bundle != null)
        intent.putExtras(bundle);//from   www. jav  a  2  s. c  o  m
    ComponentName cn = new ComponentName(packageName, className);
    intent.setComponent(cn);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}

From source file:Main.java

/**
 * Install apk//from   w w w  .  j  av a  2  s. co  m
 */
public static void installApk(Context context, File file) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:Main.java

public static void share(Context pContext, String urlToShare, String titleChosser, String subject) {

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, urlToShare);
    intent.setType("text/plain");
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    pContext.startActivity(Intent.createChooser(intent, titleChosser));
}

From source file:Main.java

public static void startInstalledAppDetailsActivity(@Nullable final Activity context) {
    if (context == null) {
        return;//from   w w  w  . j av a  2 s .com
    }
    final Intent i = new Intent();
    i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    i.setData(Uri.parse("package:" + context.getPackageName()));
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    context.startActivity(i);
}

From source file:Main.java

public static void sendScheme(Context context, String url, Bundle bundle, boolean clearTop, int flag) {
    Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
    if (bundle != null) {
        intent.putExtras(bundle);/*from   ww w . j  av  a  2s .  co m*/
    }

    if (clearTop) {
        intent.addFlags(67108864);
    }

    if (flag != 0) {
        intent.setFlags(flag);
    }

    context.startActivity(intent);
}

From source file:Main.java

@SuppressLint("NewApi")
public static void sendScheme(Fragment context, String url, Bundle bundle, boolean clearTop, int flag) {
    Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
    if (bundle != null) {
        intent.putExtras(bundle);//from   w w w  .j a va 2  s .  c  om
    }

    if (clearTop) {
        intent.addFlags(67108864);
    }

    if (flag != 0) {
        intent.setFlags(flag);
    }

    context.startActivity(intent);
}

From source file:Main.java

public static void standardUp(Activity activity) {
    Intent upIntent = NavUtils.getParentActivityIntent(activity);
    if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
        TaskStackBuilder.create(activity).addNextIntentWithParentStack(upIntent).startActivities();
    } else {/*from  w w  w.ja  va2s . c  o  m*/
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        activity.startActivity(upIntent);
        activity.finish();
    }
}

From source file:Main.java

/**
 * Returns an implicit intent for opening QuickContacts.
 *//*w  w w. j  a v  a2 s  .c  om*/
public static Intent composeQuickContactIntent(Uri contactLookupUri, int extraMode) {
    final Intent intent = new Intent(QuickContact.ACTION_QUICK_CONTACT);
    intent.setData(contactLookupUri);
    intent.putExtra(QuickContact.EXTRA_MODE, extraMode);
    // Make sure not to show QuickContacts on top of another QuickContacts.
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    return intent;
}

From source file:com.upnext.blekit.actions.BLEAction.java

/**
 * Displays a notification//from   w  ww .j a  v a 2s .  co m
 *
 * @param context Android Context, passed from the calling entity
 * @param title title for the notification
 * @param msg message and ticker for the notification
 * @param type action type that will be put as an extra into the result Intent (<code>resultIntent.putExtra("type", type);</code>)
 * @param notificationIconResId notification icon resource id
 * @param notificationId an identifier for this notification as in {@link android.app.NotificationManager#notify(int, android.app.Notification)}
 */
public static void displayNotification(Context context, String title, String msg, String type,
        int notificationIconResId, int notificationId) {
    L.d(".");

    if (BLEKit.getTargetActivityForNotifications() == null) {
        throw new IllegalArgumentException(
                "Target activity for notifications is not set. Call BLEKit.getTargetActivityForNotifications() first.");
    }

    Notification.Builder builder = new Notification.Builder(context).setContentText(msg).setTicker(msg)
            .setContentTitle(title).setAutoCancel(true).setSmallIcon(notificationIconResId);

    Intent resultIntent = new Intent(context, BLEKit.getTargetActivityForNotifications());
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    resultIntent.putExtra("type", type);

    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(notificationId, builder.build());
}