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:com.capstonecontrol.AccountsActivity.java

/**
 * Sets up the 'disconnected' screen.//from  ww  w .j  a  va2s  .  c  o  m
 */
private void setDisconnectScreenContent() {
    final SharedPreferences prefs = Util.getSharedPreferences(mContext);
    String accountName = prefs.getString(Util.ACCOUNT_NAME, "Unknown");

    // Format the disconnect message with the currently connected account
    // name
    TextView disconnectText = (TextView) findViewById(R.id.disconnect_text);
    String message = getResources().getString(R.string.disconnect_text);
    String formatted = String.format(message, accountName);
    disconnectText.setText(formatted);

    final Button disconnectButton = (Button) findViewById(R.id.disconnect);
    disconnectButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Unregister
            C2DMessaging.unregister(mContext);
            // clear the module list so that a new one will get found
            CapstoneControlActivity.modules.clear();
            // instead of finish() go back to the AccountsActivity for
            // new login.
            CapstoneControlActivity.userChanged = true;
            Intent myIntent = new Intent(v.getContext(), SplashActivity.class);
            startActivity(myIntent);
            myIntent = new Intent(v.getContext(), CapstoneControlActivity.class);
            startActivity(myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
        }
    });
}

From source file:com.zira.profile.GetProfile.java

@Override
public void processFinish(String output, String methodName) {
    // TODO Auto-generated method stub
    ZiraParser parser = new ZiraParser();
    Log.e("logout", output);
    if (methodName.equals("Logout")) {

        String result = parser.Logout(output);
        if (result.equals("0")) {
            e.putString("FBAccessToken", "");
            e.putLong("FBAccessExpires", 0);
            e.putString("Login", "");
            e.putString("Userid", "");
            e.putString("mode", "");
            e.putString("_Login", "");
            e.clear();/*from   w w  w  .j ava 2 s . c o m*/
            e.commit();

            Intent mIntent = new Intent(GetProfile.this, LoginActivity.class);
            SingleTon.getInstance().setEdited(true);
            mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(mIntent);
        } else {
            Util.alertMessage(GetProfile.this, result);
        }
    }
}

From source file:com.mono.applink.Facebook.java

/** Called when the activity is first created. */
@Override/*  w  w w . j  a  v a2 s.  c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    context = this;

    final String url = getIntent().getData().toString();

    if (url.contains("posts") || url.contains("profile.php")
            || (!url.contains("&") && !url.contains("=") && url.length() > 24))
    //1)Posts->It is impossible to launch FeedbackActivity because of permission denied.
    //With root permission and "am start" it's impossible to pass a Long extra_key...
    //2)Profile
    //3)Nickname
    {
        new FacebookUser().execute();
    } else if (url.contains("sk=inbox"))//Message
    {
        new FacebookMessage().execute();
    } else if (url.contains("event.php"))//event
    {
        new FacebookEvent().execute();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Sorry, but this type of link is not currently supported");
        builder.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        builder.setPositiveButton("Open in Browser", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent i = new Intent();
                i.setAction("android.intent.action.VIEW");
                i.addCategory("android.intent.category.BROWSABLE");
                i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                i.setData(Uri.parse(url));
                startActivity(i);
                finish();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:me.piebridge.prevent.ui.UserGuideActivity.java

private void retrieveInfo() {
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
    intent.setAction(PreventIntent.ACTION_GET_INFO);
    intent.setData(Uri.fromParts(PreventIntent.SCHEME, getPackageName(), null));
    UILog.i("sending get info broadcast");
    if (receiver == null) {
        receiver = new HookReceiver();
    }//from w w  w. j  a  v  a  2s  .  c o m
    sendOrderedBroadcast(intent, PreventIntent.PERMISSION_SYSTEM, receiver, null, 0, null, null);
}

From source file:net.olejon.mdapp.BarcodeScannerActivity.java

@Override
public void handleResult(Result result) {
    mTools.showToast(getString(R.string.barcode_scanner_wait), 0);

    String barcode = result.getText();

    RequestQueue requestQueue = Volley.newRequestQueue(mContext);

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
            getString(R.string.project_website_uri) + "api/1/barcode/?search=" + barcode,
            new Response.Listener<JSONObject>() {
                @Override//from w  ww.j a v  a 2 s. c  o  m
                public void onResponse(JSONObject response) {
                    try {
                        String medicationName = response.getString("name");

                        if (medicationName.equals("")) {
                            mTools.showToast(getString(R.string.barcode_scanner_no_results), 1);

                            finish();
                        } else {
                            SQLiteDatabase sqLiteDatabase = new SlDataSQLiteHelper(mContext)
                                    .getReadableDatabase();

                            String[] queryColumns = { SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID };
                            Cursor cursor = sqLiteDatabase.query(SlDataSQLiteHelper.TABLE_MEDICATIONS,
                                    queryColumns,
                                    SlDataSQLiteHelper.MEDICATIONS_COLUMN_NAME + " LIKE "
                                            + mTools.sqe("%" + medicationName + "%") + " COLLATE NOCASE",
                                    null, null, null, null);

                            if (cursor.moveToFirst()) {
                                long id = cursor.getLong(
                                        cursor.getColumnIndexOrThrow(SlDataSQLiteHelper.MEDICATIONS_COLUMN_ID));

                                Intent intent = new Intent(mContext, MedicationActivity.class);

                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                    if (mTools.getDefaultSharedPreferencesBoolean(
                                            "MEDICATION_MULTIPLE_DOCUMENTS"))
                                        intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK
                                                | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
                                }

                                intent.putExtra("id", id);
                                startActivity(intent);
                            }

                            cursor.close();
                            sqLiteDatabase.close();

                            finish();
                        }
                    } catch (Exception e) {
                        mTools.showToast(getString(R.string.barcode_scanner_no_results), 1);

                        Log.e("BarcodeScannerActivity", Log.getStackTraceString(e));

                        finish();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("FelleskatalogenService", error.toString());
                }
            });

    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    requestQueue.add(jsonObjectRequest);
}

From source file:org.zywx.wbpalmstar.engine.EUtil.java

public final void createSystemSwitcherShortCut(Context context, String shortCutName) {
    Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    Parcelable icon = Intent.ShortcutIconResource.fromContext(context, EResources.icon);
    addIntent.putExtra("duplicate", false);
    Intent targetIntent = new Intent(context, EBrowserActivity.class);
    targetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);
    context.sendBroadcast(addIntent);//from  w  w  w . j  ava  2  s  .  c o m
}

From source file:com.android.yijiang.kzx.http.AsyncHttpResponseHandler.java

private void gotoLogin() {
    SharedPreferences sp = ApplicationController.getInstance().getSharedPreferences("token_info", 0);
    boolean isSuccess = sp.edit().clear().commit();
    if (isSuccess) {
        JPushInterface.clearAllNotifications(ApplicationController.getInstance());
        JPushInterface.stopPush(ApplicationController.getInstance());
        Intent i = new Intent(ApplicationController.getInstance(), LoginActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        ApplicationController.getInstance().startActivity(i);
    }/*from   w ww.j  a  v a 2 s .  c om*/
}

From source file:org.cvasilak.jboss.mobile.app.service.UploadToJBossServerService.java

@Override
protected void onHandleIntent(Intent intent) {
    // initialize

    // extract details
    Server server = intent.getParcelableExtra("server");
    String directory = intent.getStringExtra("directory");
    String filename = intent.getStringExtra("filename");

    // get the json parser from the application
    JsonParser jsonParser = new JsonParser();

    // start the ball rolling...
    final NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    builder.setTicker(String.format(getString(R.string.notif_ticker), filename))
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notif_large))
            .setSmallIcon(R.drawable.ic_stat_notif_small)
            .setContentTitle(String.format(getString(R.string.notif_title), filename))
            .setContentText(getString(R.string.notif_content_init))
            // to avoid NPE on android 2.x where content intent is required
            // set an empty content intent
            .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0)).setOngoing(true);

    // notify user that upload is starting
    mgr.notify(NOTIFICATION_ID, builder.build());

    // reset ticker for any subsequent notifications
    builder.setTicker(null);/*from w  ww. j  a va 2 s.  c  o  m*/

    AbstractHttpClient client = CustomHTTPClient.getHttpClient();

    // enable digest authentication
    if (server.getUsername() != null && !server.getUsername().equals("")) {
        Credentials credentials = new UsernamePasswordCredentials(server.getUsername(), server.getPassword());

        client.getCredentialsProvider().setCredentials(
                new AuthScope(server.getHostname(), server.getPort(), AuthScope.ANY_REALM), credentials);
    }

    final File file = new File(directory, filename);
    final long length = file.length();

    try {
        CustomMultiPartEntity multipart = new CustomMultiPartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,
                new CustomMultiPartEntity.ProgressListener() {
                    @Override
                    public void transferred(long num) {
                        // calculate percentage

                        //System.out.println("transferred: " + num);

                        int progress = (int) ((num * 100) / length);

                        builder.setContentText(String.format(getString(R.string.notif_content), progress));

                        mgr.notify(NOTIFICATION_ID, builder.build());
                    }
                });

        multipart.addPart(file.getName(), new FileBody(file));

        HttpPost httpRequest = new HttpPost(server.getHostPort() + "/management/add-content");
        httpRequest.setEntity(multipart);

        HttpResponse serverResponse = client.execute(httpRequest);

        BasicResponseHandler handler = new BasicResponseHandler();
        JsonObject reply = jsonParser.parse(handler.handleResponse(serverResponse)).getAsJsonObject();

        if (!reply.has("outcome")) {
            throw new RuntimeException(getString(R.string.invalid_response));
        } else {
            // remove the 'upload in-progress' notification
            mgr.cancel(NOTIFICATION_ID);

            String outcome = reply.get("outcome").getAsString();

            if (outcome.equals("success")) {

                String BYTES_VALUE = reply.get("result").getAsJsonObject().get("BYTES_VALUE").getAsString();

                Intent resultIntent = new Intent(this, UploadCompletedActivity.class);
                // populate it
                resultIntent.putExtra("server", server);
                resultIntent.putExtra("BYTES_VALUE", BYTES_VALUE);
                resultIntent.putExtra("filename", filename);
                resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                // the notification id for the 'completed upload' notification
                // each completed upload will have a different id
                int notifCompletedID = (int) System.currentTimeMillis();

                builder.setContentTitle(getString(R.string.notif_title_uploaded))
                        .setContentText(String.format(getString(R.string.notif_content_uploaded), filename))
                        .setContentIntent(
                                // we set the (2nd param request code to completedID)
                                // see http://tinyurl.com/kkcedju
                                PendingIntent.getActivity(this, notifCompletedID, resultIntent,
                                        PendingIntent.FLAG_UPDATE_CURRENT))
                        .setAutoCancel(true).setOngoing(false);

                mgr.notify(notifCompletedID, builder.build());

            } else {
                JsonElement elem = reply.get("failure-description");

                if (elem.isJsonPrimitive()) {
                    throw new RuntimeException(elem.getAsString());
                } else if (elem.isJsonObject())
                    throw new RuntimeException(
                            elem.getAsJsonObject().get("domain-failure-description").getAsString());
            }
        }

    } catch (Exception e) {
        builder.setContentText(e.getMessage()).setAutoCancel(true).setOngoing(false);

        mgr.notify(NOTIFICATION_ID, builder.build());
    }
}

From source file:samples.piggate.com.piggateCompleteExample.Activity_Logged.java

public void logout() {

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

        loadingDialog = ProgressDialog.show(this, "Singing Out", "Wait a few seconds", false);

        //Request a session close for the logged user
        _piggate.RequestCloseSession().setListenerRequest(new Piggate.PiggateCallBack() {

            //Method onComplete for JSONObject
            @Override/*  w  w  w . ja  va  2 s  . com*/
            public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {

                loadingDialog.dismiss();
                Service_Notify.logout = true;

                //Go back to the main activity
                Intent slideactivity = new Intent(Activity_Logged.this, Activity_Main.class);
                slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                Bundle bndlanimation = ActivityOptions
                        .makeCustomAnimation(getApplicationContext(), R.anim.slidefromleft, R.anim.slidetoright)
                        .toBundle();
                startActivity(slideactivity, bndlanimation);
            }

            //Method onError for JSONObject
            @Override
            public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                Service_Notify.logout = false;
                loadingDialog.dismiss();
                errorDialog.show();
                _piggate.reload();
            }

            //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 internet conexion is not working displays an error message
        networkErrorDialog.show();
    }
}

From source file:cm.aptoide.pt.DownloadQueueService.java

private void setFinishedNotification(int apkidHash, String localPath) {

    String apkid = notifications.get(apkidHash).get("apkid");
    int size = Integer.parseInt(notifications.get(apkidHash).get("intSize"));
    String version = notifications.get(apkidHash).get("version");

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification);
    contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification);
    contentView.setTextViewText(R.id.download_notification_name,
            getString(R.string.finished_download_message) + " " + apkid + " v." + version);
    contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES,
            size * KBYTES_TO_BYTES, false);

    Intent onClick = new Intent("pt.caixamagica.aptoide.INSTALL_APK", Uri.parse("apk:" + apkid));
    onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt.RemoteInTab");
    onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    onClick.putExtra("localPath", localPath);
    onClick.putExtra("apkid", apkid);
    onClick.putExtra("apkidHash", apkidHash);
    onClick.putExtra("isUpdate", Boolean.parseBoolean(notifications.get(apkid.hashCode()).get("isUpdate")));
    /*Changed by Rafael Campos*/
    onClick.putExtra("version", notifications.get(apkid.hashCode()).get("version"));
    Log.d("Aptoide-DownloadQueuService",
            "finished notification apkidHash: " + apkidHash + " localPath: " + localPath);

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0);

    Notification notification = new Notification(R.drawable.ic_notification,
            getString(R.string.finished_download_alrt) + " " + apkid, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.contentView = contentView;

    // Set the info for the notification panel.
    notification.contentIntent = onClickAction;
    //       notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Send the notification.
    // We use the position because it is a unique number.  We use it later to cancel.
    notificationManager.notify(apkidHash, notification);

    //      Log.d("Aptoide-DownloadQueueService", "Notification Set");

}