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 boolean installApp(Context context, String filePath) {
    if (filePath != null && filePath.length() > 4
            && filePath.toLowerCase().substring(filePath.length() - 4).equals(".apk")) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        File file = new File(filePath);
        if (file.exists() && file.isFile() && file.length() > 0) {
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            return true;
        }// ww w.  ja  v a 2s. c o m
    }
    return false;
}

From source file:Main.java

/**
 * install app/*www. j  a  va2 s.  com*/
 * 
 * @param context
 * @param filePath
 * @return whether apk exist
 */
public static boolean install(Context context, String filePath) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    File file = new File(filePath);
    if (file != null && file.length() > 0 && file.exists() && file.isFile()) {
        i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
        return true;
    }
    return false;
}

From source file:Main.java

public static void feedback(Context context, String feedBackEmailId, String emailSubject, String msg) {

    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { feedBackEmailId });
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, msg);
    emailIntent.setType("message/rfc822");
    emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (isIntentAvailable(context, emailIntent)) {
        context.startActivity(emailIntent);
    } else {/*from w w  w .  java  2 s.c  om*/
        Toast.makeText(context, "No Email Application Found", Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

public static boolean installNormal(Context context, String filePath) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    File file = new File(filePath);
    if (file == null || !file.exists() || !file.isFile() || file.length() <= 0) {
        return false;
    } else {/*w  ww .ja v  a 2 s .co m*/
        intent.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
        return true;
    }
}

From source file:Main.java

public static void actionStart(Activity activity, Class cls, Bundle bundle, int... intentFlags) {
    Intent intent = new Intent(activity, cls);
    if (intentFlags != null) {
        for (int i = 0; i < intentFlags.length; i++) {
            if (intentFlags[i] != 0) {
                if (i == 0) {
                    intent.setFlags(intentFlags[i]);
                } else {
                    intent.addFlags(intentFlags[i]);
                }//from   ww w  .  ja v a  2  s .  c  om
            }
        }
    }
    if (bundle != null) {
        intent.putExtras(bundle);
    }
    activity.startActivity(intent);
}

From source file:net.openid.appauth.AuthorizationManagementActivity.java

/**
 * Creates an intent to handle the completion of an authorization flow. This restores
 * the original AuthorizationManagementActivity that was created at the start of the flow.
 * @param context the package context for the app.
 * @param responseUri the response URI, which carries the parameters describing the response.
 *///from  w  w w. ja  va2  s  .c om
public static Intent createResponseHandlingIntent(Context context, Uri responseUri) {
    Intent intent = createBaseIntent(context);
    intent.setData(responseUri);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return intent;
}

From source file:com.arellomobile.android.push.PushGCMIntentService.java

private static void generateNotification(Context context, Intent intent, Handler handler) {
    Bundle extras = intent.getExtras();// w w w.  j  a  v  a2 s . c  o m
    if (extras == null) {
        return;
    }

    extras.putBoolean("foregroud", GeneralUtils.isAppOnForeground(context));

    String title = (String) extras.get("title");
    String link = (String) extras.get("l");

    // empty message with no data
    Intent notifyIntent;
    if (link != null) {
        // we want main app class to be launched
        notifyIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
        notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {
        notifyIntent = new Intent(context, PushHandlerActivity.class);
        notifyIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        // pass all bundle
        notifyIntent.putExtra("pushBundle", extras);
    }

    // first string will appear on the status bar once when message is added
    CharSequence appName = context.getPackageManager().getApplicationLabel(context.getApplicationInfo());
    if (null == appName) {
        appName = "";
    }

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationFactory notificationFactory;

    //is this banner notification?
    String bannerUrl = (String) extras.get("b");

    //also check that notification layout has been placed in layout folder
    int layoutId = context.getResources().getIdentifier(BannerNotificationFactory.sNotificationLayout, "layout",
            context.getPackageName());

    if (layoutId != 0 && bannerUrl != null) {
        notificationFactory = new BannerNotificationFactory(context, extras, appName.toString(), title,
                PushManager.sSoundType, PushManager.sVibrateType);
    } else {
        notificationFactory = new SimpleNotificationFactory(context, extras, appName.toString(), title,
                PushManager.sSoundType, PushManager.sVibrateType);
    }
    notificationFactory.generateNotification();
    notificationFactory.addSoundAndVibrate();
    notificationFactory.addCancel();

    Notification notification = notificationFactory.getNotification();

    notification.contentIntent = PendingIntent.getActivity(context, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    if (mSimpleNotification) {
        manager.notify(PushManager.MESSAGE_ID, notification);
    } else {
        manager.notify(PushManager.MESSAGE_ID++, notification);
    }

    generateBroadcast(context, extras);
}

From source file:com.arantius.tivocommander.Utils.java

public final static boolean onOptionsItemSelected(MenuItem item, Activity srcActivity, boolean homeIsBack) {
    if (android.R.id.home == item.getItemId() && homeIsBack) {
        srcActivity.finish();// w w  w.  jav  a  2s.  c  om
        return true;
    }

    Class<? extends Activity> targetActivity = Utils.activityForMenuId(item.getItemId());
    if (targetActivity == null) {
        Utils.logError("Unknown menu item ID: " + Integer.toString(item.getItemId()));
        return false;
    }
    Intent intent = new Intent(srcActivity, targetActivity);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    srcActivity.startActivity(intent);
    return true;
}

From source file:com.jaguarlandrover.auto.remote.vehicleentry.RviService.java

static void sendNotification(Context ctx, String action, String... extras) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    boolean fire = prefs.getBoolean("pref_fire_notifications", true);

    if (!fire)/*  w  w w .  j  a v  a  2s .  co m*/
        return;

    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx).setSmallIcon(R.drawable.rvi_not)
            .setAutoCancel(true).setContentTitle(ctx.getResources().getString(R.string.app_name))
            .setContentText(action);

    Intent targetIntent = new Intent(ctx, LockActivity.class);
    int j = 0;
    for (String ex : extras) {
        targetIntent.putExtra("_extra" + (++j), ex);
        targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    }
    PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, targetIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);
    nm.notify(0, builder.build());
}

From source file:com.dnielfe.manager.utils.SimpleUtils.java

public static void createShortcut(Activity main, String path) {
    File file = new File(path);

    try {//from  w  w w .  java 2  s  .c  om
        // Create the intent that will handle the shortcut
        Intent shortcutIntent = new Intent(main, Browser.class);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        shortcutIntent.putExtra(Browser.EXTRA_SHORTCUT, path);

        // The intent to send to broadcast for register the shortcut intent
        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, file.getName());
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(main, R.drawable.ic_launcher));
        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        main.sendBroadcast(intent);

        Toast.makeText(main, main.getString(R.string.shortcutcreated), Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Toast.makeText(main, main.getString(R.string.error), Toast.LENGTH_SHORT).show();
    }
}