List of usage examples for android.content Context NOTIFICATION_SERVICE
String NOTIFICATION_SERVICE
To view the source code for android.content Context NOTIFICATION_SERVICE.
Click Source Link
From source file:com.etime.ETimeActivity.java
/** * Notify the user with the message "message". Notification is set to * on-going, on-going is needed to tell android not to kill the app. * The phone with vibrate, and light up on notification. If the message * is the exact same message as the last message notified then the * notification is not set again.//from w w w .j a va2 s . c o m * @param message Message to notify user with */ protected void notify(String message) { if (message.equalsIgnoreCase(lastNotificationMessage)) { return; } else { lastNotificationMessage = message; } int icon = R.drawable.icon; long when = System.currentTimeMillis(); Context context = getApplicationContext(); CharSequence contentTitle = "ETime"; Intent notificationIntent = new Intent(this, ETimeActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); notification.flags |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.setLatestEventInfo(context, contentTitle, message, contentIntent); mManager.notify("ETime", APP_ID, notification); }
From source file:com.clearcenter.mobile_demo.mdAuthenticatorActivity.java
public void onCreate(Bundle bundle) { Log.i(TAG, "onCreate(" + bundle + ")"); super.onCreate(bundle); setContentView(R.layout.login_activity); account_manager = AccountManager.get(this); Log.i(TAG, "loading data from Intent"); final Intent intent = getIntent(); nickname = intent.getStringExtra(PARAM_NICKNAME); username = intent.getStringExtra(PARAM_USERNAME); hostname = intent.getStringExtra(PARAM_HOSTNAME); request_new_account = nickname == null; confirm_credentials = intent.getBooleanExtra(PARAM_CONFIRM_CREDENTIALS, false); Log.i(TAG, "new account? " + request_new_account + ", confirm credentials? " + confirm_credentials); scroll_view = (ScrollView) findViewById(R.id.scroll_view); message = (TextView) findViewById(R.id.message); nickname_label = (TextView) findViewById(R.id.nickname_label); nickname_edit = (EditText) findViewById(R.id.nickname_edit); nickname_label.setVisibility(request_new_account ? View.VISIBLE : View.GONE); nickname_edit.setVisibility(request_new_account ? View.VISIBLE : View.GONE); if (nickname != null) nickname_edit.setText(nickname); hostname_label = (TextView) findViewById(R.id.hostname_label); hostname_edit = (EditText) findViewById(R.id.hostname_edit); hostname_label.setVisibility(request_new_account ? View.VISIBLE : View.GONE); hostname_edit.setVisibility(request_new_account ? View.VISIBLE : View.GONE); if (hostname != null) hostname_edit.setText(hostname); username_label = (TextView) findViewById(R.id.username_label); username_edit = (EditText) findViewById(R.id.username_edit); username_label.setVisibility(request_new_account ? View.VISIBLE : View.GONE); username_edit.setVisibility(request_new_account ? View.VISIBLE : View.GONE); if (username != null) username_edit.setText(username); password_edit = (EditText) findViewById(R.id.password_edit); if (confirm_credentials) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager notification_manager; notification_manager = (NotificationManager) getApplicationContext().getSystemService(ns); notification_manager.cancelAll(); Log.i(TAG, "TODO: Cancel all notifications?"); }/*from w w w .java2s. co m*/ if (!TextUtils.isEmpty(nickname)) nickname_edit.setText(nickname); if (request_new_account) message.setText(getText(R.string.login_activity_new_account)); else if (confirm_credentials) { message.setText(getText(R.string.login_activity_confirm_credentials)); } try { mdSSLUtil.DisableSecurity(); } catch (GeneralSecurityException e) { Toast.makeText(getApplicationContext(), e.getMessage(), 4).show(); } }
From source file:com.matze5800.paupdater.Functions.java
public static void Notify(Context context, String text) { Log.i("notify", text); Notification.Builder nBuilder; nBuilder = new Notification.Builder(context); Intent resultIntent = new Intent(context, Cancel.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(Cancel.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); nBuilder.setContentIntent(resultPendingIntent); nBuilder.setSmallIcon(R.drawable.ic_launcher); nBuilder.setContentTitle("PA Updater"); nBuilder.setContentText(text);//from w w w .j a v a 2 s . co m nBuilder.setAutoCancel(false); nBuilder.setOngoing(true); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(1, nBuilder.build()); }
From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java
@Override public void onCreate() { super.onCreate(); Log.i(TAG, "OnCreate"); locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); // Stop-detection PI stationaryAlarmPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_ALARM_ACTION), 0); registerReceiver(stationaryAlarmReceiver, new IntentFilter(STATIONARY_ALARM_ACTION)); // Stationary region PI stationaryRegionPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_REGION_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); registerReceiver(stationaryRegionReceiver, new IntentFilter(STATIONARY_REGION_ACTION)); // Stationary location monitor PI stationaryLocationPollingPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_LOCATION_MONITOR_ACTION), 0); registerReceiver(stationaryLocationMonitorReceiver, new IntentFilter(STATIONARY_LOCATION_MONITOR_ACTION)); // One-shot PI (TODO currently unused) singleUpdatePI = PendingIntent.getBroadcast(this, 0, new Intent(SINGLE_LOCATION_UPDATE_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); registerReceiver(singleUpdateReceiver, new IntentFilter(SINGLE_LOCATION_UPDATE_ACTION)); /////* w w w . j a v a 2s .co m*/ // DISABLED // Listen to Cell-tower switches (NOTE does not operate while suspended) //telephonyManager.listen(phoneStateListener, LISTEN_CELL_LOCATION); // PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wakeLock.acquire(); // Location criteria criteria = new Criteria(); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(true); criteria.setCostAllowed(true); }
From source file:com.keylesspalace.tusky.util.NotificationManager.java
public static void createNotificationChannels(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { android.app.NotificationManager mNotificationManager = (android.app.NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String[] channelIds = new String[] { CHANNEL_MENTION, CHANNEL_FOLLOW, CHANNEL_BOOST, CHANNEL_FAVOURITE };/*from w w w . j a v a 2 s .c om*/ int[] channelNames = { R.string.notification_channel_mention_name, R.string.notification_channel_follow_name, R.string.notification_channel_boost_name, R.string.notification_channel_favourite_name }; int[] channelDescriptions = { R.string.notification_channel_mention_descriptions, R.string.notification_channel_follow_description, R.string.notification_channel_boost_description, R.string.notification_channel_favourite_description }; List<NotificationChannel> channels = new ArrayList<>(4); for (int i = 0; i < channelIds.length; i++) { String id = channelIds[i]; String name = context.getString(channelNames[i]); String description = context.getString(channelDescriptions[i]); int importance = android.app.NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(id, name, importance); channel.setDescription(description); channel.enableLights(true); channel.enableVibration(true); channel.setShowBadge(true); channels.add(channel); } //noinspection ConstantConditions mNotificationManager.createNotificationChannels(channels); } }
From source file:com.scoreflex.ScoreflexGcmClient.java
protected static boolean onBroadcastReceived(Context context, Intent intent, int iconResource, Class<? extends Activity> activity) { Bundle extras = intent.getExtras();//from w w w. j a v a 2 s .co m if (extras.isEmpty()) { // has effect of unparcelling Bundle return false; } String customDataJson = extras.getString(SCOREFLEX_CUSTOM_DATA_EXTRA_KEY); if (null == customDataJson) { return false; } try { JSONObject customData = new JSONObject(customDataJson); JSONObject data = customData.getJSONObject(SCOREFLEX_NOTIFICATION_EXTRA_KEY); JSONObject sfxData = data.optJSONObject("data"); if (data.getInt("code") < Scoreflex.NOTIFICATION_TYPE_CHALLENGE_INVITATION) { return false; } String targetPlayerId = sfxData.optString("targetPlayerId"); String loggedPlayerId = ScoreflexRestClient.getPlayerId(context); if (!targetPlayerId.equals(loggedPlayerId)) { return false; } PendingIntent pendingIntent = buildPendingIntent(data, context, activity); Notification notification = buildNotification(extras.getString("alert"), context, iconResource, pendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(data.getInt("code"), notification); intent.removeExtra(SCOREFLEX_CUSTOM_DATA_EXTRA_KEY); } catch (JSONException e1) { } return false; }
From source file:android.example.com.squawker.fcm.SquawkFirebaseMessageService.java
/** * Create and show a simple notification containing the received FCM message * * @param data Map which has the message data in it *///ww w. j a v a2s . c om private void sendNotification(Map<String, String> data) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Create the pending intent to launch the activity PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); String author = data.get(JSON_KEY_AUTHOR); String message = data.get(JSON_KEY_MESSAGE); // If the message is longer than the max number of characters we want in our // notification, truncate it and add the unicode character for ellipsis if (message.length() > NOTIFICATION_MAX_CHARACTERS) { message = message.substring(0, NOTIFICATION_MAX_CHARACTERS) + "\u2026"; } Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_duck) .setContentTitle(String.format(getString(R.string.notification_message), author)) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:androidx.core.app.NotificationManagerCompat.java
private NotificationManagerCompat(Context context) { mContext = context; mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.SystemMonitor.java
private int systemNotice() { int t = START_STICKY; Log.e(SystemMonitor.class.getSimpleName(), "call me redundant BABY! onStartCommand service"); int myID = android.os.Process.myPid(); // The intent to launch when the user clicks the expanded notification Intent intent = new Intent(this, MyHealthHubWithFragments.class); // Intent intent = new Intent(); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0); Notification notice = new Notification.Builder(getApplicationContext()).setSmallIcon(R.drawable.ic_launcher) .setWhen(System.currentTimeMillis()).setContentTitle(getPackageName()) .setContentText("System Monitor running").setContentIntent(pendIntent).getNotification(); notice.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(myID, notice); return t;// w ww .j a v a 2 s . co m }
From source file:com.mutu.gpstracker.streaming.CustomUpload.java
private void notifyError(Context context, Exception e) { Log.e(TAG, "Custom upload failed", e); String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); int icon = R.drawable.ic_maps_indicator_current_position; CharSequence tickerText = context.getText(R.string.customupload_failed); long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context appContext = context.getApplicationContext(); CharSequence contentTitle = tickerText; CharSequence contentText = e.getMessage(); Intent notificationIntent = new Intent(context, CustomUpload.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(appContext, contentTitle, contentText, contentIntent); notification.flags = Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(NOTIFICATION_ID, notification); }