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:it.feio.android.omninotes.async.DataBackupIntentService.java

/**
 * Creation of notification on operations completed
 *///  w  ww .  j a v a 2  s.  c  om
private void createNotification(Intent intent, Context mContext, String title, String message, File backupDir) {

    // The behavior differs depending on intent action
    Intent intentLaunch;
    if (DataBackupIntentService.ACTION_DATA_IMPORT.equals(intent.getAction())
            || DataBackupIntentService.ACTION_DATA_IMPORT_SPRINGPAD.equals(intent.getAction())) {
        intentLaunch = new Intent(mContext, MainActivity.class);
        intentLaunch.setAction(Constants.ACTION_RESTART_APP);
    } else {
        intentLaunch = new Intent();
    }
    // Add this bundle to the intent
    intentLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intentLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // Creates the PendingIntent
    PendingIntent notifyIntent = PendingIntent.getActivity(mContext, 0, intentLaunch,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationsHelper mNotificationsHelper = new NotificationsHelper(mContext);
    mNotificationsHelper.createNotification(R.drawable.ic_content_save_white_24dp, title, notifyIntent)
            .setMessage(message).setRingtone(prefs.getString("settings_notification_ringtone", null))
            .setLedActive();
    if (prefs.getBoolean("settings_notification_vibration", true))
        mNotificationsHelper.setVibration();
    mNotificationsHelper.show();
}

From source file:com.tealeaf.TeaLeaf.java

protected void reset() {
    group.removeView(glView);/*from   ww w  .j  a  v a 2  s .com*/
    glViewPaused = false;
    glView.destroy();
    NativeShim.reset();
    Intent intent = getIntent();
    overridePendingTransition(0, 0);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    finish();
    overridePendingTransition(0, 0);
    startActivity(intent);
}

From source file:gov.nasa.arc.geocam.geocam.GeoCamService.java

private void buildNotification(CharSequence title, CharSequence notifyText) {
    Intent notificationIntent = new Intent(getApplication(), GeoCamMobile.class);
    //notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    if (mNotification == null) {
        mNotification = new Notification(R.drawable.camera_48x48, notifyText, System.currentTimeMillis());
        mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
        mNotification.flags |= Notification.FLAG_NO_CLEAR;
    }/*  w  w  w .ja  va2  s .c o  m*/
    mNotification.setLatestEventInfo(getApplicationContext(), title, notifyText, contentIntent);
}

From source file:com.dycody.android.idealnote.async.DataBackupIntentService.java

/**
 * Creation of notification on operations completed
 *///from  ww w  . j av a 2  s .c  o m
private void createNotification(Intent intent, Context mContext, String title, String message, File backupDir) {

    // The behavior differs depending on intent action
    Intent intentLaunch;
    if (DataBackupIntentService.ACTION_DATA_IMPORT.equals(intent.getAction())
            || DataBackupIntentService.ACTION_DATA_IMPORT_SPRINGPAD.equals(intent.getAction())) {
        intentLaunch = new Intent(mContext, MainActivity.class);
        intentLaunch.setAction(Constants.ACTION_RESTART_APP);
    } else {
        intentLaunch = new Intent();
    }
    // Add this bundle to the intent
    intentLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intentLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // Creates the PendingIntent
    PendingIntent notifyIntent = PendingIntent.getActivity(mContext, 0, intentLaunch,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationsHelper mNotificationsHelper = new NotificationsHelper(mContext);
    mNotificationsHelper
            .createNotification(com.dycody.android.idealnote.R.drawable.ic_content_save_white_24dp, title,
                    notifyIntent)
            .setMessage(message).setRingtone(prefs.getString("settings_notification_ringtone", null))
            .setLedActive();
    if (prefs.getBoolean("settings_notification_vibration", true))
        mNotificationsHelper.setVibration();
    mNotificationsHelper.show();
}

From source file:org.wso2.emm.agent.services.operation.OperationManager.java

/**
 * Open Google Play store application with an application given.
 *
 * @param packageName - Application package name.
 *//*  w  w w  .j  av  a2  s . co  m*/
public void triggerGooglePlayApp(String packageName) {
    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "triggerGooglePlayApp started.");
    }

    try {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse(Constants.GOOGLE_PLAY_APP_URI + packageName));
        context.startActivity(intent);
        if (Constants.DEBUG_MODE_ENABLED) {
            Log.d(TAG, "triggerGooglePlayApp called app store.");
        }
    } catch (ActivityNotFoundException e) {
        String error = "App store is not installed. Cannot install the app";
        // Handling the exception when the market place is missing in the device
        Log.e(TAG, error, e);
        Preference.putString(context, context.getResources().getString(R.string.app_install_status),
                context.getResources().getString(R.string.app_status_value_download_failed));
        Preference.putString(context, context.getResources().getString(R.string.app_install_failed_message),
                error);
    }
}

From source file:com.irccloud.android.activity.ImageViewerActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_imageviewer, menu);

    if (getIntent() != null && getIntent().getDataString() != null) {
        Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse(
                getIntent().getDataString().replace(getResources().getString(R.string.IMAGE_SCHEME), "http")));
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT,
                getIntent().getDataString().replace(getResources().getString(R.string.IMAGE_SCHEME), "http"));
        intent.putExtra(ShareCompat.EXTRA_CALLING_PACKAGE, getPackageName());
        intent.putExtra(ShareCompat.EXTRA_CALLING_ACTIVITY,
                getPackageManager().getLaunchIntentForPackage(getPackageName()).getComponent());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_TASK);

        MenuItem shareItem = menu.findItem(R.id.action_share);
        ShareActionProviderHax share = (ShareActionProviderHax) MenuItemCompat.getActionProvider(shareItem);
        share.onShareActionProviderSubVisibilityChangedListener = this;
        share.setShareIntent(intent);//  ww  w . jav a2s .c o m
    }
    return true;
}

From source file:com.cbtec.eliademy.EliademyLms.java

/**
 * Executes the request./* w  w w  .j a  v  a2 s.  co  m*/
 * 
 * This method is called from the WebView thread. To do a non-trivial amount
 * of work, use: cordova.getThreadPool().execute(runnable);
 * 
 * To run on the UI thread, use:
 * cordova.getActivity().runOnUiThread(runnable);
 * 
 * @param action
 *            The action to execute.
 * @param rawArgs
 *            The exec() arguments in JSON form.
 * @param callbackContext
 *            The callback context used when calling back into JavaScript.
 * @return Whether the action was valid.
 * @throws JSONException
 */
@Override
public boolean execute(String action, JSONArray data, final CallbackContext callbackContext)
        throws JSONException {

    Log.i("HLMS", action);

    if ((action.compareTo("openfilesrv") == 0)) {
        try {
            Uri fileuri = Uri.parse(data.getString(0));
            Intent intent = new Intent(Intent.ACTION_VIEW);
            String mimeextn = android.webkit.MimeTypeMap.getFileExtensionFromUrl(data.getString(0));
            if (mimeextn.isEmpty()) {
                mimeextn = data.getString(0).substring(data.getString(0).indexOf(".") + 1);
                ;
            }
            String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeextn);
            Log.i("HLMS", fileuri + "  " + mimetype);
            intent.setDataAndType(fileuri, mimetype);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            cordova.getActivity().getApplicationContext().startActivity(intent);
            callbackContext.success();
        } catch (Exception e) {
            Log.e("HLMS", "exception", e);
            callbackContext.error(0);
        }
        return true;
    } else if ((action.compareTo("getfilesrv") == 0)) {
        this.mCallbackContext = callbackContext;
        cordova.getThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType("*/*");// TODO: Restrict file types
                    cordova.startActivityForResult(EliademyLms.this, intent, submitFileCode);
                } catch (Exception e) {
                    Log.e("HLMS", "exception", e);
                    callbackContext.error(0);
                }
                return;
            }
        });
    } else if ((action.compareTo("initservice") == 0)) {
        if (!mIsBound) {
            this.mCallbackContext = callbackContext;
            JSONObject tmp = new JSONObject(data.getString(0));
            String sname = tmp.getString("servicename");
            if (sname.contains("eliademy")) {
                mServiceName = "com.cbtec.serviceeliademy";
            } else {
                // From url determine version 2.2, 2.3, 2.4 and change
                mServiceName = "com.cbtec.service" + sname;
            }
            Log.i("HLMS", "Connecting to service: " + mServiceName);
            doBindService();
        } else {
            callbackContext.success();
        }
        return true;
    } else {
        final String aAction = action;
        final JSONArray aData = data;
        String mappedCmd = null;
        try {
            mappedCmd = mapExecCommand(aData.getString(0));
        } catch (JSONException e) {
            Log.e("HLMS", "exception", e);
        }
        if (mappedCmd == null) {
            Log.i("HLMS", "LMS service call failed " + mappedCmd);
            callbackContext.error(0);// TODO : error enum
            return false;
        }

        final String execCmd = mappedCmd;
        cordova.getThreadPool().execute(new Runnable() {
            @Override
            @SuppressLint("NewApi")
            public void run() {
                Log.i("HLMS", "Runner execute " + aAction + aData.toString());
                if (aAction.compareTo("lmsservice") == 0) {
                    try {
                        String retval = null;
                        Log.i("HLMS", "Execute cmd: " + execCmd);
                        if (execCmd.compareTo("initialize") == 0) {
                            if (mIBinder.initializeService(aData.getString(1))) {
                                String token = mIBinder.eliademyGetWebServiceToken();
                                callbackContext.success(token);
                                return;
                            }
                        } else if (execCmd.compareTo("deinitialize") == 0) {
                            if (mIBinder.deInitializeService(aData.getString(1))) {
                                doUnbindService();
                                callbackContext.success();
                                return;
                            }
                        } else if (execCmd.compareTo("pushregister") == 0) {
                            Log.i("pushdata", aData.getString(1));
                            if (mIBinder.registerPushNotifications(aData.getString(1))) {
                                callbackContext.success();
                                return;
                            }
                        } else if (execCmd.compareTo("pushunregister") == 0) {
                            Log.i("pushdata", aData.getString(1));
                            if (mIBinder.unregisterPushNotifications(aData.getString(1))) {
                                callbackContext.success();
                                return;
                            }
                        } else if (execCmd.compareTo("servicetoken") == 0) {
                            retval = mIBinder.eliademyGetWebServiceToken();
                        } else if (execCmd.compareTo("siteinfo") == 0) {
                            retval = mIBinder.eliademyGetSiteInformation(aData.getString(1));
                        } else if (execCmd.compareTo("get_user_courses") == 0) {
                            retval = mIBinder.eliademyGetUsersCourses(aData.getString(1));
                        } else if (execCmd.compareTo("get_user_forums") == 0) {
                            retval = mIBinder.eliademyGetUserForums(aData.getString(1));
                        } else if (execCmd.compareTo("get_user_info") == 0) {
                            retval = mIBinder.eliademyGetUserInformation(aData.getString(1));
                        } else if (execCmd.compareTo("exec_webservice") == 0) {
                            Log.i("HLMS", "Execute webservice");
                            retval = mIBinder.eliademyExecWebService(aData.getString(0), aData.getString(1));
                        } else if (execCmd.compareTo("course_get_contents") == 0) {
                            retval = mIBinder.eliademyGetCourseContents(aData.getString(1));
                        } else if (execCmd.compareTo("course_get_enrolled_users") == 0) {
                            retval = mIBinder.eliademyGetEnrolledUsers(aData.getString(1));
                        } else {
                            Log.i("HLMS", "LMS service failed " + execCmd);
                            callbackContext.error(0);// TODO : error enum
                        }
                        if (!retval.isEmpty()) {
                            Log.i("HLMS", "LMS service call success");
                            callbackContext.success(retval);
                        } else {
                            Log.i("HLMS", "LMS service call failed");
                            callbackContext.error(0);// TODO : error enum
                        }
                    } catch (Exception e) {
                        Log.e("HLMS", "exception", e);
                        callbackContext.error(e.getMessage());
                        return;
                    }
                } else {
                    Log.i("LMS", "Unsupported action call !!");
                    callbackContext.error(0);
                    return;
                }
            }
        });
    }
    return true;
}

From source file:com.parse.ParsePushBroadcastReceiver.java

/**
 * Called when the push notification is opened by the user. Sends analytics info back to Parse
 * that the application was opened from this push notification. By default, this will navigate
 * to the {@link Activity} returned by {@link #getActivity(Context, Intent)}. If the push contains
 * a 'uri' parameter, an Intent is fired to view that URI with the Activity returned by
 * {@link #getActivity} in the back stack.
 *
 * @param context//from w  ww  .  j a  v  a2  s .  c o m
 *      The {@code Context} in which the receiver is running.
 * @param intent
 *      An {@code Intent} containing the channel and data of the current push notification.
 */
protected void onPushOpen(Context context, Intent intent) {
    // Send a Parse Analytics "push opened" event
    ParseAnalytics.trackAppOpenedInBackground(intent);

    String uriString = null;
    try {
        JSONObject pushData = new JSONObject(intent.getStringExtra(KEY_PUSH_DATA));
        uriString = pushData.optString("uri", null);
    } catch (JSONException e) {
        PLog.e(TAG, "Unexpected JSONException when receiving push data: ", e);
    }

    Class<? extends Activity> cls = getActivity(context, intent);
    Intent activityIntent;
    if (uriString != null) {
        activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriString));
    } else {
        activityIntent = new Intent(context, cls);
    }

    activityIntent.putExtras(intent.getExtras());
    /*
      In order to remove dependency on android-support-library-v4
      The reason why we differentiate between versions instead of just using context.startActivity
      for all devices is because in API 11 the recommended conventions for app navigation using
      the back key changed.
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TaskStackBuilderHelper.startActivities(context, cls, activityIntent);
    } else {
        activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(activityIntent);
    }
}

From source file:de.jamoo.muzei.WallSource.java

@Override
public void onCustomCommand(int id) {
    super.onCustomCommand(id);

    if (id == COMMAND_ID_SHARE) {
        Artwork currentArtwork = getCurrentArtwork();
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");

        Uri artUrl = currentArtwork.getImageUri();
        if (DEBUG)
            Log.d(TAG, "artUrl: " + artUrl);

        String author = currentArtwork.getByline();
        if (DEBUG)
            Log.d(TAG, "author: " + author);

        String playUrl = "http://play.google.com/store/apps/details?id=" + getPackageName();
        if (DEBUG)
            Log.d(TAG, "playUrl: " + playUrl);

        shareIntent.putExtra(Intent.EXTRA_TEXT,
                "My wallpaper today is " + currentArtwork.getTitle() + " by " + author + " \n" + artUrl + " \n"
                        + "from the " + getString(R.string.app_name) + " app\n"
                        + "Get it now on the PlayStore! " + playUrl);

        shareIntent = Intent.createChooser(shareIntent, "Share Wallpaper");
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(shareIntent);/*from   w ww  .  j  a  v  a2 s  .c o  m*/
    }
}