List of usage examples for android.app PendingIntent FLAG_CANCEL_CURRENT
int FLAG_CANCEL_CURRENT
To view the source code for android.app PendingIntent FLAG_CANCEL_CURRENT.
Click Source Link
From source file:com.jtxdriggers.android.ventriloid.VentriloidService.java
private Notification createNotification(String text, short type, short id) { Intent notifIntent = new Intent(this, Connected.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(VentriloidService.this); switch (type) { case VentriloEvents.V3_EVENT_LOGIN_COMPLETE: case VentriloEvents.V3_EVENT_USER_LOGIN: case VentriloEvents.V3_EVENT_USER_LOGOUT: case VentriloEvents.V3_EVENT_USER_CHAN_MOVE: notifBuilder.setSmallIcon(R.drawable.headset).setContentText("Connected to " + server.getServername()) .setTicker(text).setContentTitle("Ventriloid").setOngoing(true).setAutoCancel(false); break;/* w w w .j a v a2s . com*/ case VentriloEvents.V3_EVENT_USER_PAGE: notifBuilder.setSmallIcon(R.drawable.about).setContentText(text).setTicker(text) .setContentTitle("Page Received").setAutoCancel(true).setOngoing(false) .setDefaults(Notification.DEFAULT_VIBRATE); break; case VentriloEvents.V3_EVENT_PRIVATE_CHAT_MESSAGE: notifIntent.putExtra("id", id); Item.User u = items.getUserById(id); notifBuilder.setSmallIcon(R.drawable.comment).setContentText(text).setTicker(text) .setContentTitle(u.name + " - Private Message").setOnlyAlertOnce(true).setAutoCancel(true) .setOngoing(false).setDefaults(Notification.DEFAULT_ALL); break; case VentriloEvents.V3_EVENT_DISCONNECT: notifIntent = new Intent(this, Main.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notifBuilder.setSmallIcon(R.drawable.headset).setContentTitle("Disconnected from Server") .setContentText(text).setOngoing(true).setAutoCancel(false); if (text.contains(10 + "")) notifBuilder.setTicker("Reconnecting to Server"); else if (text.contains("call")) notifBuilder.setTicker(text); break; } PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT); notifBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.launcher)) .setContentIntent(pendingIntent); return notifBuilder.getNotification(); }
From source file:com.secupwn.aimsicd.service.CellTracker.java
/** * Description: Set or update the Detection/Status Notification * TODO: Need to add status HIGH (Orange) and SKULL (Black) * * Issues://w w w. j a v a 2 s . c o m * See: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/wiki/Status-Icons * and: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/11#issuecomment-44670204 * * [ ] We need to standardize the "contentText" and "tickerText" format * * [ ] From #91: https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/91 * * Problem: * Having multiple notifications will cause an issue with * notifications themselves AND tickerText. It seems that the * most recent notification raised would overwrite any previous, * notification or tickerText. This results in loss of information * for any notification before the last one. * * Possible Solution: * Perhaps arranging a queue implementation to deal with text * being passed into tickerText only when any previous text has * been entirely displayed. * * Dependencies: Status.java, CellTracker.java, Icon.java ( + others?) * */ void setNotification() { String tickerText; String contentText = "Phone Type " + device.getPhoneType(); if (femtoDetected || typeZeroSmsDetected) { getApplication().setCurrentStatus(Status.DANGER, vibrateEnabled, vibrateMinThreatLevel); } else if (changedLAC) { getApplication().setCurrentStatus(Status.MEDIUM, vibrateEnabled, vibrateMinThreatLevel); contentText = context.getString(R.string.hostile_service_area_changing_lac_detected); } else if (emptyNeighborCellsList) { getApplication().setCurrentStatus(Status.MEDIUM, vibrateEnabled, vibrateMinThreatLevel); contentText = context.getString(R.string.cell_doesnt_provide_any_neighbors); } else if (cellIdNotInOpenDb) { getApplication().setCurrentStatus(Status.MEDIUM, vibrateEnabled, vibrateMinThreatLevel); contentText = context.getString(R.string.cell_id_doesnt_exist_in_db); } else if (trackingFemtocell || trackingCell || monitoringCell) { getApplication().setCurrentStatus(Status.OK, vibrateEnabled, vibrateMinThreatLevel); if (trackingFemtocell) { contentText = context.getString(R.string.femtocell_detection_active); } else if (trackingCell) { contentText = context.getString(R.string.cell_tracking_active); } if (monitoringCell) { contentText = context.getString(R.string.cell_monitoring_active); } else { getApplication().setCurrentStatus(Status.IDLE, vibrateEnabled, vibrateMinThreatLevel); } } else { getApplication().setCurrentStatus(Status.IDLE, vibrateEnabled, vibrateMinThreatLevel); } Status status = getApplication().getStatus(); switch (status) { case IDLE: // GRAY contentText = context.getString(R.string.phone_type) + device.getPhoneType(); tickerText = context.getResources().getString(R.string.app_name_short) + " " + context.getString(R.string.status_idle_description); break; case OK: // GREEN tickerText = context.getResources().getString(R.string.app_name_short) + " " + context.getString(R.string.status_ok_description); break; case MEDIUM: // YELLOW // Initialize tickerText as the app name string // See multiple detection comments above. tickerText = context.getResources().getString(R.string.app_name_short); if (changedLAC) { //Append changing LAC text contentText = context.getString(R.string.hostile_service_area_changing_lac_detected); tickerText += " - " + contentText; } else if (emptyNeighborCellsList) { //According to #264 contentText = context.getString(R.string.cell_doesnt_provide_any_neighbors); tickerText += " - " + contentText; } else if (cellIdNotInOpenDb) { //Append Cell ID not existing in external db text contentText = context.getString(R.string.cell_id_doesnt_exist_in_db); tickerText += " - " + contentText; } break; case DANGER: // RED tickerText = context.getResources().getString(R.string.app_name_short) + " - " + context.getString(R.string.alert_threat_detected); // Hmm, this is vague! if (femtoDetected) { contentText = context.getString(R.string.alert_femtocell_connection_detected); } else if (typeZeroSmsDetected) { contentText = context.getString(R.string.alert_silent_sms_detected); } break; default: tickerText = context.getResources().getString(R.string.main_app_name); break; } // TODO: Explanation (see above) Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.putExtra("silent_sms", typeZeroSmsDetected); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_FROM_BACKGROUND); PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ID, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); String iconType = prefs.getString(context.getString(R.string.pref_ui_icons_key), "SENSE").toUpperCase(); int iconResId = Icon.getIcon(Icon.Type.valueOf(iconType), status); Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), iconResId); int color = context.getResources().getColor(status.getColor()); Notification notification = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.tower48) .setColor(color).setLargeIcon(largeIcon).setTicker(tickerText) .setContentTitle(context.getString(R.string.status) + " " + context.getString(status.getName())) .setContentInfo(context.getResources().getString(R.string.app_name_short)) .setContentText(contentText).setOngoing(true).setAutoCancel(false).setContentIntent(contentIntent) .build(); NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, notification); }
From source file:com.magnet.mmx.client.MMXClient.java
static PendingIntent getWakeupIntent(Context context) { Intent intent = new Intent(context, MMXWakeupIntentService.class); intent.setAction(ACTION_WAKEUP);//w w w .j ava2s . c o m return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.nuvolect.deepdive.probe.DecompileApk.java
public JSONObject stopThread(String threadId) { THREAD_ID thread = THREAD_ID.valueOf(threadId); Thread myThread = null;// ww w . ja v a 2s . co m switch (thread) { case unpack_apk: myThread = m_unpackApkThread; break; case dex2jar: myThread = m_dex2jarThread; break; case optimize_dex: myThread = m_optimizeDexThread; break; case cfr: myThread = m_cfrThread; break; case jadx: myThread = m_jadxThread; break; case fern_flower: myThread = m_fernThread; break; default:// do nothing } // if( myThread != null){ // myThread.currentThread().stop();// deprecated as of API 16 jellybean // myThread.currentThread().interrupt(); // not working, does not stop thread // } /** * Not the best solution but attempts to selectively stop individual threads do not * seem to work. We need need a more robust solution for long running process management. */ Intent mStartActivity = new Intent(m_ctx, com.nuvolect.deepdive.main.MainActivity.class); int mPendingIntentId = 123456; PendingIntent mPendingIntent = PendingIntent.getActivity(m_ctx, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) m_ctx.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0); Runtime.getRuntime().exit(0); return getStatus(); }
From source file:com.jins_meme.bridge.MainActivity.java
void restart() { PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, getIntent(), PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 500, pendingIntent); finishAndRemoveTask();/*from w w w . j a v a2s .c o m*/ }
From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java
protected void getErrorNotification(String title, String text) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title) .setContentText(text)/* w w w . j a va 2 s.c om*/ .setLargeIcon(((BitmapDrawable) getResources().getDrawable(R.drawable.app_icon)).getBitmap()) .setSmallIcon(R.drawable.app_notification); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(ActivityMain.class); Intent resultIntent = new Intent(this, ActivityMain.class); stackBuilder.addNextIntent(resultIntent); PendingIntent intent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(intent); builder.setTicker(title); Notification notification = builder.build(); notification.flags = Notification.FLAG_AUTO_CANCEL; //set notification to be cleared when tapped //startForeground(ONGOING_NOTIFICATION, builder.build()); mNotificationManager.notify(ONGOING_NOTIFICATION, notification); }
From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java
protected void getWaitingForNetworkNotification() { String status = getResources().getString(R.string.status_waiting_for_network); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(String.valueOf(mPreset) + ". " + mTitle).setContentText(status) .addAction(R.drawable.content_remove, getResources().getString(R.string.cancel), getStopIntent()) .setUsesChronometer(true)/*w w w .j a va 2 s . c o m*/ .setLargeIcon(((BitmapDrawable) getResources().getDrawable(R.drawable.app_icon)).getBitmap()) .setSmallIcon(R.drawable.app_notification); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(ActivityMain.class); Intent resultIntent = new Intent(this, ActivityMain.class); stackBuilder.addNextIntent(resultIntent); PendingIntent intent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(intent); builder.setTicker(status); this.updateDetails(status); startForeground(ONGOING_NOTIFICATION, builder.build()); //mNotificationManager.notify(ONGOING_NOTIFICATION, builder.build()); }
From source file:org.broeuschmeul.android.gps.usb.provider.driver.USBGpsManager.java
/** * Disables the Usb GPS provider./*from w w w . ja va 2s . c om*/ * <p> * It will: * <ul> * <li>close the connection with the bluetooth device</li> * <li>disable the Mock Location Provider used for the bluetooth GPS</li> * <li>stop the BlueGPS4Droid service</li> * </ul> * If the bluetooth provider is closed because of a problem, a notification is displayed. */ public synchronized void disable() { notificationManager.cancel(R.string.connection_problem_notification_title); if (getDisableReason() != 0) { NotificationCompat.Builder partialServiceStoppedNotification = serviceStoppedNotificationBuilder .setWhen(System.currentTimeMillis()).setAutoCancel(true) .setContentTitle(appContext .getString(R.string.service_closed_because_connection_problem_notification_title)) .setContentText( appContext.getString(R.string.service_closed_because_connection_problem_notification, appContext.getString(getDisableReason()))); // Make the correct notification to direct the user to the correct setting if (getDisableReason() == R.string.msg_mock_location_disabled) { PendingIntent mockLocationsSettingsIntent = PendingIntent.getActivity(appContext, 0, new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS), PendingIntent.FLAG_CANCEL_CURRENT); partialServiceStoppedNotification.setContentIntent(mockLocationsSettingsIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(appContext.getString( R.string.service_closed_because_connection_problem_notification, appContext.getString(R.string.msg_mock_location_disabled_full)))); } else if (getDisableReason() == R.string.msg_no_location_permission) { PendingIntent mockLocationsSettingsIntent = PendingIntent.getActivity(appContext, 0, new Intent(callingService, GpsInfoActivity.class), PendingIntent.FLAG_CANCEL_CURRENT); USBGpsApplication.setLocationNotAsked(); partialServiceStoppedNotification.setContentIntent(mockLocationsSettingsIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(appContext.getString( R.string.service_closed_because_connection_problem_notification, appContext.getString(R.string.msg_no_location_permission)))); } Notification serviceStoppedNotification = partialServiceStoppedNotification.build(); notificationManager.notify(R.string.service_closed_because_connection_problem_notification_title, serviceStoppedNotification); sharedPreferences.edit() .putInt(appContext.getString(R.string.pref_disable_reason_key), getDisableReason()).apply(); } if (enabled) { debugLog("disabling USB GPS manager"); callingService.unregisterReceiver(permissionAndDetachReceiver); enabled = false; connectionAndReadingPool.shutdown(); Runnable closeAndShutdown = new Runnable() { @Override public void run() { try { connectionAndReadingPool.awaitTermination(10, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); } if (!connectionAndReadingPool.isTerminated()) { connectionAndReadingPool.shutdownNow(); if (connectedGps != null) { connectedGps.close(); } } } }; notificationPool.execute(closeAndShutdown); nmeaListeners.clear(); disableMockLocationProvider(); notificationPool.shutdown(); callingService.stopSelf(); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean(USBGpsProviderService.PREF_START_GPS_PROVIDER, false); editor.apply(); debugLog("USB GPS manager disabled"); } }
From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java
protected NotificationCompat.Builder getUpdateNotification(String status, String stopText, boolean updateTicker) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(String.valueOf(mPreset) + ". " + mTitle).setContentText(status) //.addAction(R.drawable.av_previous, getResources().getString(R.string.previous), getPreviousIntent()) //.addAction(R.drawable.av_stop, stopText, getStopIntent()) //.addAction(R.drawable.av_next, getResources().getString(R.string.next), getNextIntent()) .addAction(R.drawable.av_previous, null, getPreviousIntent()) .addAction(R.drawable.av_stop, null, getStopIntent()).setUsesChronometer(true) .addAction(R.drawable.av_next, null, getNextIntent()) .setLargeIcon(((BitmapDrawable) getResources().getDrawable(R.drawable.app_icon)).getBitmap()) .setSmallIcon(R.drawable.app_notification); //PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(ActivityMain.class); //stackBuilder.addNextIntent(nextIntent) Intent resultIntent = new Intent(this, ActivityMain.class); //resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP); //why is this not needed? stackBuilder.addNextIntent(resultIntent); PendingIntent intent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(intent);//from w w w .j av a 2 s .c o m if (updateTicker) { builder.setTicker(status); //startForeground(ONGOING_NOTIFICATION, builder.build()); } else { //mNotificationManager.notify(ONGOING_NOTIFICATION, builder.build()); } this.updateDetails(status); return builder; }
From source file:de.ub0r.android.callmeter.data.RuleMatcher.java
/** * Match all unmatched logs./*from w w w. ja v a 2 s . com*/ * * @param context {@link Context} * @param showStatus post status to dialog/handler * @return true if a log was matched */ static synchronized boolean match(final Context context, final boolean showStatus) { Log.d(TAG, "match(ctx, ", showStatus, ")"); long start = System.currentTimeMillis(); boolean ret = false; load(context); final ContentResolver cr = context.getContentResolver(); final Cursor cursor = cr.query(DataProvider.Logs.CONTENT_URI, DataProvider.Logs.PROJECTION, DataProvider.Logs.PLAN_ID + " = " + DataProvider.NO_ID, null, DataProvider.Logs.DATE + " ASC"); if (cursor != null && cursor.moveToFirst()) { final int l = cursor.getCount(); Handler h; if (showStatus) { h = Plans.getHandler(); if (h != null) { final Message m = h.obtainMessage(Plans.MSG_BACKGROUND_PROGRESS_MATCHER); m.arg1 = 0; m.arg2 = l; m.sendToTarget(); } } try { ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); int i = 1; do { ret |= matchLog(cr, ops, cursor); if (i % PROGRESS_STEPS == 0 || (i < PROGRESS_STEPS && i % CallMeter.TEN == 0)) { h = Plans.getHandler(); if (h != null) { final Message m = h.obtainMessage(Plans.MSG_BACKGROUND_PROGRESS_MATCHER); m.arg1 = i; m.arg2 = l; Log.d(TAG, "send progress: ", i, "/", l); m.sendToTarget(); } else { Log.d(TAG, "send progress: ", i, " handler=null"); } Log.d(TAG, "save logs.."); cr.applyBatch(DataProvider.AUTHORITY, ops); ops.clear(); Log.d(TAG, "sleeping.."); try { Thread.sleep(CallMeter.MILLIS); } catch (InterruptedException e) { Log.e(TAG, "sleep interrupted", e); } Log.d(TAG, "sleep finished"); } ++i; } while (cursor.moveToNext()); if (ops.size() > 0) { cr.applyBatch(DataProvider.AUTHORITY, ops); } } catch (IllegalStateException e) { Log.e(TAG, "illegal state in RuleMatcher's loop", e); } catch (OperationApplicationException e) { Log.e(TAG, "illegal operation in RuleMatcher's loop", e); } catch (RemoteException e) { Log.e(TAG, "remote exception in RuleMatcher's loop", e); } } try { if (cursor != null && !cursor.isClosed()) { cursor.close(); } } catch (IllegalStateException e) { Log.e(TAG, "illegal state while closing cursor", e); } if (ret) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); final boolean a80 = p.getBoolean(Preferences.PREFS_ALERT80, true); final boolean a100 = p.getBoolean(Preferences.PREFS_ALERT100, true); // check for alerts if ((a80 || a100) && plans != null && plans.size() > 0) { final long now = System.currentTimeMillis(); int alert = 0; Plan alertPlan = null; int l = plans.size(); for (int i = 0; i < l; i++) { final Plan plan = plans.valueAt(i); if (plan == null) { continue; } if (plan.nextAlert > now) { Log.d(TAG, "%s: skip alert until: %d now=%d", plan, plan.nextAlert, now); continue; } int used = DataProvider.Plans.getUsed(plan.type, plan.limitType, plan.billedAmount, plan.billedCost); int usedRate = plan.limit > 0 ? (int) ((used * CallMeter.HUNDRED) / plan.limit) : 0; if (a100 && usedRate >= CallMeter.HUNDRED) { alert = usedRate; alertPlan = plan; } else if (a80 && alert < CallMeter.EIGHTY && usedRate >= CallMeter.EIGHTY) { alert = usedRate; alertPlan = plan; } } if (alert > 0) { final NotificationManager mNotificationMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); final String t = String.format(context.getString(R.string.alerts_message), alertPlan.name, alert); NotificationCompat.Builder b = new NotificationCompat.Builder(context); b.setSmallIcon(android.R.drawable.stat_notify_error); b.setTicker(t); b.setWhen(now); b.setContentTitle(context.getString(R.string.alerts_title)); b.setContentText(t); Intent i = new Intent(context, Plans.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); b.setContentIntent(PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); mNotificationMgr.notify(0, b.build()); // set nextAlert to beginning of next day Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); alertPlan.nextAlert = cal.getTimeInMillis(); final ContentValues cv = new ContentValues(); cv.put(DataProvider.Plans.NEXT_ALERT, alertPlan.nextAlert); cr.update(DataProvider.Plans.CONTENT_URI, cv, DataProvider.Plans.ID + " = ?", new String[] { String.valueOf(alertPlan.id) }); } } } long end = System.currentTimeMillis(); Log.i(TAG, "match(): ", end - start, "ms"); return ret; }