List of usage examples for android.content Intent addFlags
public @NonNull Intent addFlags(@Flags int flags)
From source file:com.parse.f8.view.SignInActivity.java
public void finishActivity() { // Start an intent for the dispatch activity Intent intent = new Intent(SignInActivity.this, DispatchActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);//from w ww . j a v a 2 s . c o m }
From source file:org.wso2.iot.agent.services.MessageProcessor.java
@SuppressWarnings("unused") @Override//from w ww .ja v a 2 s . co m public void onReceiveAPIResult(Map<String, String> result, int requestCode) { String responseStatus; String response; if (requestCode == Constants.NOTIFICATION_REQUEST_CODE) { Preference.putLong(context, Constants.PreferenceFlag.LAST_SERVER_CALL, CommonUtils.currentDate().getTime()); Intent intent = new Intent(); intent.setAction(Constants.SYNC_BROADCAST_ACTION); context.sendBroadcast(intent); if (isWipeTriggered) { if (Constants.SYSTEM_APP_ENABLED) { CommonUtils.callSystemApp(context, Constants.Operation.WIPE_DATA, null, null); } else { Log.i(TAG, "Not the device owner."); } } if (isEnterpriseWipeTriggered) { CommonUtils.disableAdmin(context); Intent intentEnterpriseWipe = new Intent(context, ServerConfigsActivity.class); intentEnterpriseWipe.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intentEnterpriseWipe.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intentEnterpriseWipe); if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Started enterprise wipe"); } } if (isRebootTriggered) { CommonUtils.callSystemApp(context, Constants.Operation.REBOOT, null, null); } if (isUpgradeTriggered) { String schedule = Preference.getString(context, context.getResources().getString(R.string.pref_key_schedule)); CommonUtils.callSystemApp(context, Constants.Operation.UPGRADE_FIRMWARE, schedule, null); } if (isShellCommandTriggered && shellCommand != null) { CommonUtils.callSystemApp(context, Constants.Operation.EXECUTE_SHELL_COMMAND, shellCommand, null); } if (result != null) { responseStatus = result.get(Constants.STATUS_KEY); response = result.get(Constants.RESPONSE); if (Constants.Status.SUCCESSFUL.equals(responseStatus) || Constants.Status.CREATED.equals(responseStatus)) { if (response != null && !response.isEmpty()) { if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Pending Operations List: " + response); } if (Constants.DEFAULT_OWNERSHIP.equals(Constants.OWNERSHIP_COSU)) { if (!Preference.getBoolean(context, Constants.PreferenceFlag.DEVICE_INITIALIZED)) { Preference.putBoolean(context, Constants.PreferenceFlag.DEVICE_INITIALIZED, true); } } performOperation(response); } } else if (Constants.Status.AUTHENTICATION_FAILED.equals(responseStatus) && org.wso2.iot.agent.proxy.utils.Constants.REFRESH_TOKEN_EXPIRED.equals(response)) { Log.d(TAG, "Requesting credentials to obtain new token pair."); LocalNotification.stopPolling(context); Preference.putBoolean(context, Constants.TOKEN_EXPIRED, true); CommonUtils.displayNotification(context, R.drawable.ic_error_outline_white_24dp, context.getResources().getString(R.string.title_need_to_sign_in), context.getResources().getString(R.string.msg_need_to_sign_in), AuthenticationActivity.class, Constants.TOKEN_EXPIRED, Constants.SIGN_IN_NOTIFICATION_ID); } } } }
From source file:org.safegees.safegees.gui.view.MainActivity.java
private void setPermissionsAlertDialog(String message) { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(message).setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent i = getBaseContext().getPackageManager() .getLaunchIntentForPackage(getBaseContext().getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i);/* w w w. j a v a 2 s . com*/ //finish(); } }).setNegativeButton("EXIT", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void refreshNotification(Context context, boolean noTimeline) { AppSettings settings = AppSettings.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int currentAccount = sharedPrefs.getInt("current_account", 1); //int[] unreadCounts = new int[] {4, 1, 2}; // for testing int[] unreadCounts = getUnreads(context); int timeline = unreadCounts[0]; int realTimelineCount = timeline; // if they don't want that type of notification, simply set it to zero if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) { unreadCounts[0] = 0;/*from w w w.j ava 2 s . co m*/ } if (!settings.mentionsNot) { unreadCounts[1] = 0; } if (!settings.dmsNot) { unreadCounts[2] = 0; } if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) { } else { Intent markRead = new Intent(context, MarkReadService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); String shortText = getShortText(unreadCounts, context, currentAccount); String longText = getLongText(unreadCounts, context, currentAccount); // [0] is the full title and [1] is the screenname String[] title = getTitle(unreadCounts, context, currentAccount); boolean useExpanded = useExp(context); boolean addButton = addBtn(unreadCounts); if (title == null) { return; } Intent resultIntent; if (unreadCounts[1] != 0 && unreadCounts[0] == 0) { // it is a mention notification (could also have a direct message) resultIntent = new Intent(context, RedirectToMentions.class); } else if (unreadCounts[2] != 0 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // it is a direct message resultIntent = new Intent(context, RedirectToDMs.class); } else { resultIntent = new Intent(context, MainActivity.class); } PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0]) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)) .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1])) .setContentIntent(resultPendingIntent).setAutoCancel(true) .setTicker(TweetLinkUtils.removeColorHtml(shortText, settings)) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) { // inbox style notification for mentions mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // inbox style notification for direct messages mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else { // big text style for an unread count on timeline, mentions, and direct messages mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title[0], shortText); } // Light Flow notification sendToLightFlow(context, title[0], shortText); int homeTweets = unreadCounts[0]; int mentionsTweets = unreadCounts[1]; int dmTweets = unreadCounts[2]; int newC = 0; if (homeTweets > 0) { newC++; } if (mentionsTweets > 0) { newC++; } if (dmTweets > 0) { newC++; } if (settings.notifications && newC > 0) { if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); if (addButton) { // the reply and read button should be shown Intent reply; if (unreadCounts[1] == 1) { reply = new Intent(context, NotificationCompose.class); } else { reply = new Intent(context, NotificationDMCompose.class); } Log.v("username_for_noti", title[1]); sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit(); MentionsDataSource data = MentionsDataSource.getInstance(context); long id = data.getLastIds(currentAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0); sharedPrefs.edit().putLong("from_notification_long", id).commit(); sharedPrefs.edit() .putString("from_notification_text", "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings)) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel("@" + title[1] + " ").build(); // Create the notification action NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build(); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending); mBuilder.addAction(replyAction); mBuilder.addAction(action.build()); } else { // otherwise, if they can use the expanded notifications, the popup button will be shown Intent popup = new Intent(context, RedirectToPopup.class); popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); popup.putExtra("from_notification", true); PendingIntent popupPending = PendingIntent.getActivity(context, 0, popup, 0); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_popup, context.getResources().getString(R.string.popup), popupPending); mBuilder.addAction(action.build()); } // Build the notification and issues it with notification manager. notificationManager.notify(1, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } } // if there are unread tweets on the timeline, check them for favorite users if (settings.favoriteUserNotifications && realTimelineCount > 0) { favUsersNotification(currentAccount, context); } } try { ContentValues cv = new ContentValues(); cv.put("tag", "com.klinker.android.twitter/com.klinker.android.twitter.ui.MainActivity"); // add the direct messages and mentions cv.put("count", unreadCounts[1] + unreadCounts[2]); context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv); } catch (IllegalArgumentException ex) { /* Fine, TeslaUnread is not installed. */ } catch (Exception ex) { /* Some other error, possibly because the format of the ContentValues are incorrect. Log but do not crash over this. */ ex.printStackTrace(); } }
From source file:name.setup.dance.StepService.java
/** * Show a notification while this service is running. *///from ww w . j a v a 2 s . c o m private void showNotification() { CharSequence text = getText(R.string.app_name); Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis()); notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; Intent DanceStepAppIntent = new Intent(); DanceStepAppIntent.setComponent(new ComponentName(this, DanceStepApp.class)); DanceStepAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, DanceStepAppIntent, 0); notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent); mNM.notify(R.string.app_name, notification); }
From source file:com.google.zxing.client.android.CaptureActivity.java
private void handleDecodeExternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { if (source == IntentSource.NATIVE_APP_INTENT) { // Hand back whatever action they requested - this can be changed to // Intents.Scan.ACTION when // the deprecated intent is retired. Intent intent = new Intent(getIntent().getAction()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); JSONObject jsonObject = new JSONObject(); try {/*from w ww . ja va 2s . co m*/ jsonObject.put("code", rawResult.toString()); jsonObject.put("result", rawResult.getText()); jsonObject.put("type", rawResult.getBarcodeFormat()); Map<ResultMetadataType, Object> data = new Hashtable<ResultMetadataType, Object>(); @SuppressWarnings("rawtypes") Iterator iterator = data.keySet().iterator(); while (iterator.hasNext()) { final ResultMetadataType key = (ResultMetadataType) iterator.next(); jsonObject.put(key.toString(), data.get(key).toString()); } jsonObject.put("timestamp", rawResult.getTimestamp()); } catch (JSONException e) { e.printStackTrace(); } intent.putExtra(EUExCallback.F_JK_CODE, rawResult.toString()); intent.putExtra(EUExCallback.F_JK_TYPE, rawResult.getBarcodeFormat().toString()); sendReplyMessage(EUExUtil.getResIdID("return_scan_result"), intent, 0); } }
From source file:com.mobiperf.AccountSelector.java
private void getAuthToken(AccountManagerFuture<Bundle> result) { Logger.i("getAuthToken() called, result " + result); String errMsg = "Failed to get login cookie. "; Bundle bundle;/*from ww w. j av a 2s. c om*/ try { bundle = result.getResult(); Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { // User input required. (A UI will pop up for user's consent to allow // this app access account information.) Logger.i("Starting account manager activity"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } else { Logger.i("Executing getCookie task"); synchronized (this) { this.authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); this.checkinFuture = checkinExecutor.submit(new GetCookieTask()); } } } catch (OperationCanceledException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } catch (AuthenticatorException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } catch (IOException e) { Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } }
From source file:com.kiwiteam.nomiddleman.LargeGroupActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. switch (item.getItemId()) { case R.id.action_search: return true; case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; case R.id.home: Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);/* www . jav a 2 s .co m*/ return true; case R.id.action_cart: intent = new Intent(this, ShoppingCartActivity.class); startActivity(intent); return true; case R.id.account: account(); return true; case R.id.signout: conn.signout(); recreate(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.num.mobiperf.AccountSelector.java
private void getAuthToken(AccountManagerFuture<Bundle> result) { //Logger.i("getAuthToken() called, result " + result); String errMsg = "Failed to get login cookie. "; Bundle bundle;//from w w w .j av a 2 s .c om try { bundle = result.getResult(); Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT); if (intent != null) { // User input required. (A UI will pop up for user's consent to allow // this app access account information.) //Logger.i("Starting account manager activity"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } else { //Logger.i("Executing getCookie task"); synchronized (this) { this.authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); this.checkinFuture = checkinExecutor.submit(new GetCookieTask()); } } } catch (OperationCanceledException e) { //Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } catch (AuthenticatorException e) { //Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } catch (IOException e) { //Logger.e(errMsg, e); throw new RuntimeException("Can't get login cookie", e); } }
From source file:com.inloc.dr.StepService.java
/** * Show a notification while this service is running. *///from ww w . j a v a 2 s.c om private void showNotification() { CharSequence text = getText(R.string.app_name); Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis()); notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; Intent pedometerIntent = new Intent(); pedometerIntent.setComponent(new ComponentName(this, DeadReckoning.class)); pedometerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, pedometerIntent, 0); notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent); mNM.notify(R.string.app_name, notification); }