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.tt.jobtracker.MainActivity.java

private void selectItem(int position) {

    // update the main content by replacing fragments
    Fragment fragment = null;//from  w w w  .  j a  va2s.  co  m

    if (position == 0) {
        showTaskListMenu(true);
        fragment = new TaskListFragment();
    } else if (position == 1) {
        fragment = new SettingsFragment();

    } else if (position == 2) {

        final SharedPreferences username = getApplicationContext().getSharedPreferences(Shared.Username, 0);
        final SharedPreferences password = getApplicationContext().getSharedPreferences(Shared.Password, 0);
        SharedPreferences.Editor editor = username.edit();
        editor.putString("Loginuser", null); // Storing string
        editor.commit();
        SharedPreferences.Editor editor1 = password.edit();
        editor1.putString("LoginPass", null); // Storing string
        editor1.commit();
        Intent intent;
        finish();
        Shared.LoggedInUser = null;
        intent = new Intent(MainActivity.this, Login.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getApplicationContext().startActivity(intent);
    }

    if (fragment != null) {
        Bundle args = new Bundle();
        fragment.setArguments(args);

        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
    }
    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mMenuTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:io.teak.sdk.Teak.java

@Override
public void onReceive(Context inContext, Intent intent) {
    final Context context = inContext.getApplicationContext();

    if (!Teak.isEnabled()) {
        Log.e(LOG_TAG, "Teak is disabled, ignoring onReceive().");
        return;/*from  w w w  .j ava2s. co m*/
    }

    String action = intent.getAction();

    if (GCM_RECEIVE_INTENT_ACTION.equals(action)) {
        final TeakNotification notif = TeakNotification.remoteNotificationFromIntent(context, intent);
        if (notif == null) {
            return;
        }

        // Send Notification Received Metric
        Session.whenUserIdIsReadyRun(new Session.SessionRunnable() {
            @Override
            public void run(Session session) {
                HashMap<String, Object> payload = new HashMap<>();
                payload.put("app_id", session.appConfiguration.appId);
                payload.put("user_id", session.userId());
                payload.put("platform_id", notif.teakNotifId);

                new Request("/notification_received", payload, session).run();
            }
        });
    } else if (action.endsWith(TeakNotification.TEAK_NOTIFICATION_OPENED_INTENT_ACTION_SUFFIX)) {
        Bundle bundle = intent.getExtras();

        // Cancel any updates pending
        TeakNotification.cancel(context, bundle.getInt("platformId"));

        // Launch the app
        if (!bundle.getBoolean("noAutolaunch")) {
            if (Teak.isDebug) {
                Log.d(LOG_TAG,
                        "Notification (" + bundle.getString("teakNotifId") + ") opened, auto-launching app.");
            }
            Intent launchIntent = context.getPackageManager()
                    .getLaunchIntentForPackage(context.getPackageName());
            launchIntent.addCategory("android.intent.category.LAUNCHER");
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            launchIntent.putExtras(bundle);
            if (bundle.getString("deepLink") != null) {
                launchIntent.setData(Uri.parse(bundle.getString("deepLink")));
            }
            context.startActivity(launchIntent);
        } else {
            if (Teak.isDebug) {
                Log.d(LOG_TAG, "Notification (" + bundle.getString("teakNotifId")
                        + ") opened, NOT auto-launching app (noAutoLaunch flag present, and set to true).");
            }
        }

        // Send broadcast
        if (Teak.localBroadcastManager != null) {
            Intent broadcastEvent = new Intent(TeakNotification.LAUNCHED_FROM_NOTIFICATION_INTENT);
            broadcastEvent.putExtras(bundle);
            Teak.localBroadcastManager.sendBroadcast(broadcastEvent);
        }
    } else if (action.endsWith(TeakNotification.TEAK_NOTIFICATION_CLEARED_INTENT_ACTION_SUFFIX)) {
        Bundle bundle = intent.getExtras();
        TeakNotification.cancel(context, bundle.getInt("platformId"));
    }

}

From source file:com.aware.Aware.java

public static void reset(Context c) {
    if (!c.getPackageName().equals("com.aware"))
        return;/*from  w w  w.  j  a v a  2 s  .c o m*/

    String device_id = Aware.getSetting(c, Aware_Preferences.DEVICE_ID);

    //Remove all settings
    c.getContentResolver().delete(Aware_Settings.CONTENT_URI, null, null);

    //Read default client settings
    SharedPreferences prefs = c.getSharedPreferences(c.getPackageName(), Context.MODE_PRIVATE);
    PreferenceManager.setDefaultValues(c, c.getPackageName(), Context.MODE_PRIVATE, R.xml.aware_preferences,
            true);
    prefs.edit().commit();

    Map<String, ?> defaults = prefs.getAll();
    for (Map.Entry<String, ?> entry : defaults.entrySet()) {
        Aware.setSetting(c, entry.getKey(), entry.getValue());
    }

    //Restore old Device ID
    Aware.setSetting(c, Aware_Preferences.DEVICE_ID, device_id);

    //Turn off all active plugins
    Cursor active_plugins = c.getContentResolver().query(Aware_Plugins.CONTENT_URI, null,
            Aware_Plugins.PLUGIN_STATUS + "=" + Plugins_Manager.PLUGIN_ACTIVE, null, null);
    if (active_plugins != null && active_plugins.moveToFirst()) {
        do {
            Aware.stopPlugin(c,
                    active_plugins.getString(active_plugins.getColumnIndex(Aware_Plugins.PLUGIN_PACKAGE_NAME)));
        } while (active_plugins.moveToNext());
        active_plugins.close();
    }

    //Apply fresh state
    Intent aware_apply = new Intent(Aware.ACTION_AWARE_REFRESH);
    c.sendBroadcast(aware_apply);

    Intent preferences = new Intent(c, Aware_Preferences.class);
    preferences.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    c.startActivity(preferences);
}

From source file:org.ohthehumanity.carrie.CarrieActivity.java

/** Called when the activity is first created. */
@Override//from www .ja v  a2 s  . c o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mServerName = "";
    setContentView(R.layout.main);

    // instantiate our preferences backend
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // set callback function when settings change
    mPreferences.registerOnSharedPreferenceChangeListener(this);

    if (mPreferences.getString("server", null) == null) {
        setStatus("Server not set");
    } else if (mPreferences.getString("port", null) == null) {
        setStatus("Port not configured");
    }

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm.getActiveNetworkInfo().getType() != ConnectivityManager.TYPE_WIFI) {

        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
        dlgAlert.setTitle("WiFi not active");
        dlgAlert.setMessage(
                "This application is usually used on a local network over a WiFi. Open WiFi settings?");
        dlgAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                    //Yes button clicked
                    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    final ComponentName cn = new ComponentName("com.android.settings",
                            "com.android.settings.wifi.WifiSettings");
                    intent.setComponent(cn);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    //Log.i(TAG, "Not opening wifi");
                    //No button clicked
                    break;
                }
            }
        });

        dlgAlert.setNegativeButton("No", null);
        dlgAlert.setCancelable(true);
        dlgAlert.create().show();
    }

    updateTitle();
    updateSkipLabels();
    updateServerName();
}

From source file:com.rainmakerlabs.bleepsample.BleepService.java

private void localNotification(String title, String message, Intent notificationIntent, String failMsg,
        int notifyId) {
    if (!testIntent(notificationIntent)) {
        //if (!BleepActivity.isTesting)
        //   return;
        notificationIntent = null;//  www. j  av  a 2  s  . com
        if (!failMsg.equalsIgnoreCase(""))
            message = failMsg;
    }
    if (notificationIntent == null) {
        notificationIntent = new Intent(this, BleepActivity.rootClass);
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        notificationIntent.setAction(Intent.ACTION_MAIN);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    }
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    if (message == null || message.equalsIgnoreCase(""))
        return;
    if (title == null || title.equalsIgnoreCase(""))
        title = getString(R.string.app_name);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setTicker(message).setWhen(System.currentTimeMillis())
            .setAutoCancel(true).setContentTitle(title).setContentText(message).setContentIntent(contentIntent)
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(notifyId, builder.build());
}

From source file:it.feio.android.omninotes.async.DataBackupIntentService.java

/**
 * Creation of notification on operations completed
 *//* w  ww  . j  a v a2  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(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:id.zelory.tanipedia.activity.BeritaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_berita);
    toolbar = (Toolbar) findViewById(R.id.anim_toolbar);

    setSupportActionBar(toolbar);//from w w  w .j  a v a  2s.  com
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle("Berita Terbaru");

    animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);

    drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
    setUpNavDrawer();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.getMenu().getItem(1).setChecked(true);
    TextView nama = (TextView) navigationView.findViewById(R.id.nama);
    nama.setText(PrefUtils.ambilString(this, "nama"));
    TextView email = (TextView) navigationView.findViewById(R.id.email);
    email.setText(PrefUtils.ambilString(this, "email"));
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.cuaca:
                intent = new Intent(BeritaActivity.this, CuacaActivity.class);
                break;
            case R.id.berita:
                return true;
            case R.id.tanya:
                intent = new Intent(BeritaActivity.this, TanyaActivity.class);
                break;
            case R.id.harga:
                intent = new Intent(BeritaActivity.this, KomoditasActivity.class);
                break;
            case R.id.logout:
                PrefUtils.simpanString(BeritaActivity.this, "nama", null);
                intent = new Intent(BeritaActivity.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                return true;
            case R.id.tentang:
                intent = new Intent(BeritaActivity.this, TentangActivity.class);
                startActivity(intent);
                return true;
            default:
                return true;
            }
            startActivity(intent);
            finish();
            return true;
        }
    });
    imageHeader = (ImageView) findViewById(R.id.header);
    recyclerView = (RecyclerView) findViewById(R.id.scrollableview);

    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);

    fabButton = (FabButton) findViewById(R.id.determinate);
    fabButton.showProgress(true);
    new DownloadData().execute();
    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fabButton.showProgress(true);
            new DownloadData().execute();
        }
    });
}

From source file:com.heightechllc.breakify.MainActivity.java

/**
 * Handles a new intent, either from onNewIntent() or onCreate()
 * @param intent The intent to handle//from   w ww  .  ja  v  a  2 s  .  c  o  m
 * @return Whether we should attempt to restore the saved timer state. Will be false when
 *  this method opens another Activity.
 */
private boolean handleIntent(Intent intent) {
    boolean shouldRestoreSavedTimer = true;

    if (intent.getBooleanExtra(EXTRA_SNOOZE, false)) {
        // The activity was launched from the expanded notification's "Snooze" action

        snoozeTimer();
        // In case user didn't interact with the RingingActivity, and instead snoozed directly
        //  from the notification
        AlarmRinger.stop(this);

        // Don't restore, since we're about to open a new Activity
        shouldRestoreSavedTimer = false;

    } else if (intent.getBooleanExtra(EXTRA_ALARM_RING, false)) {
        // The Activity was launched from AlarmReceiver, meaning the timer finished and we
        //  need to ring the alarm

        Intent ringingIntent = new Intent(this, RingingActivity.class);
        // Pass along FLAG_ACTIVITY_NO_USER_ACTION if it was set when calling this activity
        if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NO_USER_ACTION) != 0)
            ringingIntent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
        startActivityForResult(ringingIntent, RingingActivity.REQUEST_ALARM_RING);

        // Don't restore, since we're about to open a new Activity
        shouldRestoreSavedTimer = false;

    } else if (intent.getBooleanExtra(EXTRA_SCHEDULED_START, false)) {
        // The Activity was launched from ScheduledStartReceiver, meaning it's time for the
        //  scheduled start

        // Show a dialog prompting the user to start
        new AlertDialog.Builder(this).setTitle(R.string.scheduled_dialog_title)
                .setMessage(R.string.scheduled_dialog_message)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        // Start the timer
                        circleTimer.performClick();
                    }
                }).setNeutralButton(R.string.action_settings, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        // Show the settings activity with the Scheduled Start settings
                        Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
                        intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
                                ScheduledStartSettingsFragment.class.getName());
                        intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_TITLE,
                                R.string.pref_category_scheduled);
                        startActivity(intent);
                    }
                }).setNegativeButton(R.string.cancel, null).show();
    }

    return shouldRestoreSavedTimer;
}

From source file:id.zelory.tanipedia.activity.KomoditasActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_komoditas);
    toolbar = (Toolbar) findViewById(R.id.anim_toolbar);
    setSupportActionBar(toolbar);//from ww  w.  j a  v  a  2 s  .  c o m
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle("Harga Komoditas");

    animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);

    drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
    setUpNavDrawer();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.getMenu().getItem(3).setChecked(true);
    TextView nama = (TextView) navigationView.findViewById(R.id.nama);
    nama.setText(PrefUtils.ambilString(this, "nama"));
    TextView email = (TextView) navigationView.findViewById(R.id.email);
    email.setText(PrefUtils.ambilString(this, "email"));
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.cuaca:
                intent = new Intent(KomoditasActivity.this, CuacaActivity.class);
                break;
            case R.id.berita:
                intent = new Intent(KomoditasActivity.this, BeritaActivity.class);
                break;
            case R.id.tanya:
                intent = new Intent(KomoditasActivity.this, TanyaActivity.class);
                break;
            case R.id.harga:
                return true;
            case R.id.logout:
                PrefUtils.simpanString(KomoditasActivity.this, "nama", null);
                intent = new Intent(KomoditasActivity.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                return true;
            case R.id.tentang:
                intent = new Intent(KomoditasActivity.this, TentangActivity.class);
                startActivity(intent);
                return true;
            default:
                return true;
            }
            startActivity(intent);
            finish();
            return true;
        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.scrollableview);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);

    imageHeader = (ImageView) findViewById(R.id.header);
    imageHeader.setVisibility(View.GONE);

    fabButton = (FabButton) findViewById(R.id.determinate);
    fabButton.showProgress(true);
    new DownloadData().execute();
    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fabButton.showProgress(true);
            new DownloadData().execute();
        }
    });
}

From source file:com.etalio.android.EtalioBase.java

/**
 * Redirects the end user to Etalio sign in. Sign in will happen through the
 * Etalio app if installed, else through the web browser.
 *
 * <code>mEtalio.initiateEtalioSignIn(this, "profile.basic.r profile.email.r");</code>
 *
 * @param activity the activity used to call Etalio sign in.
 * @param scope    scopes for the sign in. The scopes should be separated by spaces, like "profile.basic.r profile.email.r"
 *///from   w  w  w.  j  a v a 2  s .  co  m
public void initiateEtalioSignIn(Activity activity, String scope) {
    resetState();
    if (!isEtalioInstalled(activity)) {
        activity.startActivity(new Intent(Intent.ACTION_VIEW, getSignInUrl(scope)));
    } else {
        Intent etalio = new Intent();
        etalio.setClassName("com.etalio.android", "com.etalio.android.app.ui.activity.SingleSignOnActivity");
        etalio.putExtra(EXTRA_CLIENT_ID, mClientId);
        etalio.putExtra(EXTRA_PACKAGE_NAME, activity.getPackageName());
        etalio.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        activity.startActivityForResult(etalio, REQUEST_CODE_SSO);
    }
}