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:samples.piggate.com.piggateCompleteExample.Activity_SingUp.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize the Piggate object

    getSupportActionBar().setTitle("Register");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    setContentView(R.layout.activity_register);
    //EditTexts for user email and password
    editEmail = (EditText) findViewById(R.id.editText1);
    editPass = (EditText) findViewById(R.id.editText2);
    Button register = (Button) findViewById(R.id.buttonregister);

    errorDialog = new AlertDialog.Builder(this).create();
    errorDialog.setTitle("Login error");
    errorDialog.setMessage("There is an error with the login");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override/*w  w w . ja v  a2  s.  c  o m*/
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    networkErrorDialog = new AlertDialog.Builder(this).create();
    networkErrorDialog.setTitle("Network error");
    networkErrorDialog.setMessage("There is an error with the network connection");
    networkErrorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    //OnClick listener for the login button
    //Handles the register request to the server with the email and password fields
    //and the login request if the fields are correct
    register.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {
            String email = editEmail.getText().toString();
            String pass = editPass.getText().toString();

            //If the internet connection is working
            if (checkInternetConnection() == true) {

                if (editEmail.getText().toString().equals("") || editPass.getText().toString().equals("")) {
                    if (editEmail.getText().toString().equals(""))
                        editEmail.setError("Enter your email");
                    if (editPass.getText().toString().equals(""))
                        editPass.setError("Enter your password");
                } else {
                    loadingDialog = ProgressDialog.show(v.getContext(), "Singing Up", "Wait a few seconds",
                            true);
                    RequestParams params = new RequestParams();
                    params.put("email", email);
                    params.put("password", pass);

                    //Request of the Piggate object. Handles the register into the application
                    // and the login with the user email and password
                    _piggate.RequestNewUser(params).setListenerRequest(new Piggate.PiggateCallBack() {

                        //Method onComplete for JSONObject
                        //When the request is correct start Activity_Logged activity
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            Intent slideactivity = new Intent(Activity_SingUp.this, Activity_Logged.class);
                            slideactivity
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                                    R.anim.slidefromright, R.anim.slidetoleft).toBundle();
                            startActivity(slideactivity, bndlanimation);
                        }

                        //Method onError for JSONObject
                        //If there's an error with the request displays the error message to the user
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    errorDialog.show();
                                }
                            });
                        }

                        //Method onComplete for JSONArray
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }

                        //Method onError for JSONArray
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }
                    }).exec();
                }
            } else { //If the internet connection is not working
                networkErrorDialog.show();
            }
        }
    });
}

From source file:com.msdpe.authenticationdemo.AuthService.java

/**
 * Handles logging the user out including:
 * -deleting cookies so their login with a provider won't be cached in the web view
 * -removing the userdata from the shared preferences
 * -setting the current user object on the client to logged out
 * -optionally redirects to the login page if requested
 * @param shouldRedirectToLogin/*from w w w  .  j av a2  s . com*/
 */
public void logout(boolean shouldRedirectToLogin) {
    //Clear the cookies so they won't auto login to a provider again
    CookieSyncManager.createInstance(mContext);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    //Clear the user id and token from the shared preferences
    SharedPreferences settings = mContext.getSharedPreferences("UserData", 0);
    SharedPreferences.Editor preferencesEditor = settings.edit();
    preferencesEditor.clear();
    preferencesEditor.commit();
    //Clear the user and return to the auth activity
    mClient.logout();
    //Take the user back to the auth activity to relogin if requested
    if (shouldRedirectToLogin) {
        Intent logoutIntent = new Intent(mContext, AuthenticationActivity.class);
        logoutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(logoutIntent);
    }
}

From source file:io.samsungsami.example.SAMInBLEws.SAMIDeviceActivity.java

private void startLoginActivity() {
    SAMISession.getInstance().reset();//  w ww . j  a  va  2s  .  c  o m
    Intent activityIntent = new Intent(this, SAMILoginActivity.class);
    activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(activityIntent);
    finish();
}

From source file:com.mediatek.mms.ext.DefaultMmsConfigExt.java

public void openUrl(Context context, String url) {
    Log.d(TAG, "openUrl, url=" + url);
    Uri theUri = Uri.parse(url);/*from   w w w. j  ava2  s .c  om*/
    Intent intent = new Intent(Intent.ACTION_VIEW, theUri);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    context.startActivity(intent);
}

From source file:org.sigimera.app.android.GCMIntentService.java

@Override
protected final void onMessage(final Context context, final Intent message) {
    final Intent msg = message;
    this.mainThreadHandler.post(new Runnable() {
        public void run() {
            ApplicationController controller = ApplicationController.getInstance();
            controller.init(getApplicationContext(), getSharedPreferences(Constants.PREFS_NAME, 0), null);
            String authToken = controller.getSharedPreferences().getString("auth_token", null);
            final String type = msg.getStringExtra("sig_message_type");
            if (type.equalsIgnoreCase("NEW_CRISIS")) {
                /**/*from   w w  w .j ava 2  s  . c  o  m*/
                 * XXX: Blocks UI: Shift this code into a separate
                 * background thread
                 */
                Crisis crisis = PersistanceController.getInstance().getCrisis(authToken,
                        msg.getStringExtra("crisis_id"));

                StringBuffer message = new StringBuffer();
                if (crisis != null) {
                    message.append(crisis.getID());
                    message.append(" was stored successfully!");
                } else {
                    message.append("Not able to get crisis!");
                }
                Toast.makeText(getApplicationContext(), message.toString(), Toast.LENGTH_LONG).show();
            } else if (type.equalsIgnoreCase("PING")) {
                String ns = Context.NOTIFICATION_SERVICE;
                NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

                Intent notificationIntent = new Intent();
                PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
                        notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

                Notification notification = new NotificationCompat.Builder(getApplicationContext())
                        .setContentTitle("Sigimera PING!")
                        .setContentText("Congratulations, push notifcation received!")
                        .setSmallIcon(R.drawable.sigimera_logo).setAutoCancel(true)
                        .setDefaults(Notification.DEFAULT_ALL).setContentIntent(contentIntent).build();

                mNotificationManager.notify(Constants.PING_ID, notification);
            } else if (type.equalsIgnoreCase("CRISIS_ALERT")) {
                String ns = Context.NOTIFICATION_SERVICE;
                NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

                /**
                 * XXX: Not working with random ID. That makes always the
                 * latest notification clickable, but not the older ones.
                 */
                int notificationID = new Random().nextInt();
                Intent notificationIntent = new Intent(getApplicationContext(), CrisisAlertActivity.class);
                notificationIntent.putExtra("notification_id", notificationID);
                notificationIntent.putExtra("crisis_id", msg.getStringExtra("crisis_id"));
                notificationIntent.putExtra("crisis_type", msg.getStringExtra("crisis_type"));
                PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
                        notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

                Notification notification = new NotificationCompat.Builder(getApplicationContext())
                        .setContentTitle("CRISIS ALERT!")
                        .setContentText("Crisis found: " + msg.getStringExtra("crisis_id"))
                        .setSmallIcon(R.drawable.alert_red).setOngoing(true).setAutoCancel(true)
                        .setDefaults(Notification.DEFAULT_ALL).setContentIntent(contentIntent).build();

                mNotificationManager.notify(notificationID, notification);
            } else if (type.equalsIgnoreCase("SHARED_CRISIS")) {
                Intent intent = new Intent(GCMIntentService.this, CrisisActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra(Constants.CRISIS_ID, msg.getStringExtra("crisis_id"));
                intent.putExtra(Constants.WINDOW_TYPE, Constants.WINDOW_TYPE_SHARED_CRISIS);
                startActivity(intent);
            } else if (type.equalsIgnoreCase("UNREGISTER_DEVICE")) {
                GCMRegistrar.unregister(ApplicationController.getInstance().getApplicationContext());
            } else if (type.equalsIgnoreCase("REFRESH")) {
                LocationUpdaterHttpHelper locUpdater = new LocationUpdaterHttpHelper();
                Location loc = LocationController.getInstance().getLastKnownLocation();
                if (loc != null) {
                    String latitude = loc.getLatitude() + "";
                    String longitude = loc.getLongitude() + "";
                    if (authToken != null) {
                        locUpdater.execute(authToken, latitude, longitude);
                    }
                } else {
                    // TODO: Notify the user that the update location flow
                    // has not worked.
                }
            }
        }
    });
}

From source file:com.google.android.apps.chrometophone.C2DMReceiver.java

private Intent getLaunchIntent(Context context, String url, String title, String sel) {
    Intent intent = null;
    String number = parseTelephoneNumber(sel);
    if (number != null) {
        intent = new Intent("android.intent.action.DIAL", Uri.parse("tel:" + number));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
        cm.setText(number);/*  ww w  . j a  v  a2 s.  c o  m*/
    } else if (sel != null && sel.length() > 0) {
        // No intent for selection - just copy to clipboard
        ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
        cm.setText(sel);
    } else {
        final String GMM_PACKAGE_NAME = "com.google.android.apps.maps";
        final String GMM_CLASS_NAME = "com.google.android.maps.MapsActivity";

        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (isMapsURL(url)) {
            intent.setClassName(GMM_PACKAGE_NAME, GMM_CLASS_NAME);
        }

        // Fall back if we can't resolve intent (i.e. app missing)
        PackageManager pm = context.getPackageManager();
        if (null == intent.resolveActivity(pm)) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
    }
    return intent;
}

From source file:com.example.sabeeh.helloworld.AuthService.java

/**
 * Handles logging the user out including:
 * -deleting cookies so their login with a provider won't be cached in the web view
 * -removing the userdata from the shared preferences
 * -setting the current user object on the client to logged out
 * -optionally redirects to the login page if requested
 * @param shouldRedirectToLogin//from www.j a v a  2s.c  o  m
 */
public void logout(boolean shouldRedirectToLogin) {
    //Clear the cookies so they won't auto login to a provider again
    CookieSyncManager.createInstance(mContext);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    //Clear the user id and token from the shared preferences
    ClearcacheUserToken();
    //Clear the user and return to the auth activity
    mClient.logout();
    //Take the user back to the auth activity to relogin if requested
    if (shouldRedirectToLogin) {
        Intent logoutIntent = new Intent(mContext, LoginActivity.class);
        logoutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(logoutIntent);
    }
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPush.java

public static void openMainActivityOnNotificationClick(Context ctx) {
    Intent intentToLaunch = ctx.getPackageManager().getLaunchIntentForPackage(ctx.getPackageName());

    if (intentToLaunch != null) {
        intentToLaunch.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
        ctx.startActivity(intentToLaunch);
    }/*from  w ww.  j  a  v a 2s  .c o m*/
}

From source file:com.android.mail.browse.AttachmentActionHandler.java

public void shareAttachment() {
    if (mAttachment.contentUri == null) {
        return;/* www  .  j  a v  a2  s .  c  o  m*/
    }

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    final Uri uri = Utils.normalizeUri(mAttachment.contentUri);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    intent.setType(Utils.normalizeMimeType(mAttachment.getContentType()));

    try {
        mContext.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        // couldn't find activity for SEND intent
        LogUtils.e(LOG_TAG, "Couldn't find Activity for intent", e);
    }
}

From source file:com.nanostuffs.yurdriver.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*  w  w w .  j  a  v a  2 s .  com*/
private 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();

}