List of usage examples for android.support.v4.app NotificationManagerCompat from
public static NotificationManagerCompat from(Context context)
From source file:com.xclong.vehiclemonitordemo.service.CommunicationService.java
@Override public void onCreate() { super.onCreate(); TAG = this.getClass().getSimpleName(); communicationService = CommunicationService.newInstance(); mNotificationManager = NotificationManagerCompat.from(getApplicationContext()); Log.e(TAG, "??"); //TODO //from ww w.j a va2s . c om if (!hasRegesiger) { hasRegesiger = true; Log.e(TAG, ""); IntentFilter filter1 = new IntentFilter(Const.ACTION2); registerReceiver(receiver, filter1); IntentFilter filter2 = new IntentFilter(Const.ACTION3); registerReceiver(receiver, filter2); IntentFilter filter3 = new IntentFilter(Const.ACTION6); registerReceiver(receiver, filter3); IntentFilter filter4 = new IntentFilter(Const.ACTION5); registerReceiver(receiver, filter4); IntentFilter filter5 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED); registerReceiver(receiver, filter5); IntentFilter filter6 = new IntentFilter(Const.ACTION7); registerReceiver(receiver, filter6); IntentFilter filter7 = new IntentFilter(Const.ACTION9); registerReceiver(receiver, filter7); } vdao = new VehicledInfoDao(this); adao = new AbnormalInfoDao(this); connectSocket(); }
From source file:com.sumang.chatdemo.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *///from w ww .j a va 2 s .c o m private void sendNotification(String title, String messageBody) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setGroup("ABC") .setGroupSummary(true).setSmallIcon(R.drawable.messenger_bubble_small_white) .setColor(getResources().getColor(R.color.colorAccent)).setContentTitle(title) .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext()); notificationManager.notify(Util.createID() /* ID of notification */, notificationBuilder.build()); }
From source file:com.morlunk.leeroy.LeeroyUpdateService.java
private void handleCheckUpdates(Intent intent, boolean notify, ResultReceiver receiver) { List<LeeroyApp> appList = LeeroyApp.getApps(getPackageManager()); if (appList.size() == 0) { return;/* w w w . j av a 2 s. c o m*/ } List<LeeroyAppUpdate> updates = new LinkedList<>(); List<LeeroyApp> notUpdatedApps = new LinkedList<>(); List<LeeroyException> exceptions = new LinkedList<>(); for (LeeroyApp app : appList) { try { String paramUrl = app.getJenkinsUrl() + "/api/json?tree=lastSuccessfulBuild[number,url]"; URL url = new URL(paramUrl); URLConnection conn = url.openConnection(); Reader reader = new InputStreamReader(conn.getInputStream()); JsonReader jsonReader = new JsonReader(reader); jsonReader.beginObject(); jsonReader.nextName(); jsonReader.beginObject(); int latestSuccessfulBuild = 0; String buildUrl = null; while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if ("number".equals(name)) { latestSuccessfulBuild = jsonReader.nextInt(); } else if ("url".equals(name)) { buildUrl = jsonReader.nextString(); } else { throw new RuntimeException("Unknown key " + name); } } jsonReader.endObject(); jsonReader.endObject(); jsonReader.close(); if (latestSuccessfulBuild > app.getJenkinsBuild()) { LeeroyAppUpdate update = new LeeroyAppUpdate(); update.app = app; update.newBuild = latestSuccessfulBuild; update.newBuildUrl = buildUrl; updates.add(update); } else { notUpdatedApps.add(app); } } catch (MalformedURLException e) { e.printStackTrace(); CharSequence appName = app.getApplicationInfo().loadLabel(getPackageManager()); exceptions.add(new LeeroyException(app, getString(R.string.invalid_url, appName), e)); } catch (IOException e) { e.printStackTrace(); exceptions.add(new LeeroyException(app, e)); } } if (notify) { NotificationManagerCompat nm = NotificationManagerCompat.from(this); if (updates.size() > 0) { NotificationCompat.Builder ncb = new NotificationCompat.Builder(this); ncb.setSmallIcon(R.drawable.ic_stat_update); ncb.setTicker(getString(R.string.updates_available)); ncb.setContentTitle(getString(R.string.updates_available)); ncb.setContentText(getString(R.string.num_updates, updates.size())); ncb.setPriority(NotificationCompat.PRIORITY_LOW); ncb.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); Intent appIntent = new Intent(this, AppListActivity.class); appIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); ncb.setContentIntent( PendingIntent.getActivity(this, 0, appIntent, PendingIntent.FLAG_CANCEL_CURRENT)); ncb.setAutoCancel(true); NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); for (LeeroyAppUpdate update : updates) { CharSequence appName = update.app.getApplicationInfo().loadLabel(getPackageManager()); style.addLine(getString(R.string.notify_app_update, appName, update.app.getJenkinsBuild(), update.newBuild)); } style.setSummaryText(getString(R.string.app_name)); ncb.setStyle(style); ncb.setNumber(updates.size()); nm.notify(NOTIFICATION_UPDATE, ncb.build()); } if (exceptions.size() > 0) { NotificationCompat.Builder ncb = new NotificationCompat.Builder(this); ncb.setSmallIcon(R.drawable.ic_stat_error); ncb.setTicker(getString(R.string.error_checking_updates)); ncb.setContentTitle(getString(R.string.error_checking_updates)); ncb.setContentText(getString(R.string.click_to_retry)); ncb.setPriority(NotificationCompat.PRIORITY_LOW); ncb.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); ncb.setContentIntent(PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); ncb.setAutoCancel(true); ncb.setNumber(exceptions.size()); nm.notify(NOTIFICATION_ERROR, ncb.build()); } } if (receiver != null) { Bundle results = new Bundle(); results.putParcelableArrayList(EXTRA_UPDATE_LIST, new ArrayList<>(updates)); results.putParcelableArrayList(EXTRA_NO_UPDATE_LIST, new ArrayList<>(notUpdatedApps)); results.putParcelableArrayList(EXTRA_EXCEPTION_LIST, new ArrayList<>(exceptions)); receiver.send(0, results); } }
From source file:com.google.android.apps.santatracker.WearNotificationService.java
/** * Builds a simple notification on the wearable. *//* w ww.j ava 2 s . com*/ private void buildTakeoffNotification(String content) { Log.v(TAG, "buildTakeoffNotification: " + content); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentText(content) .setSmallIcon(R.drawable.ic_launcher); // TODO workaround for bug for always displaying notifications builder.setContentTitle(""); Bitmap largeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.santa_notification_background); builder.setLargeIcon(largeIcon); //We want to know when the notification is dismissed, so we can dismiss it on the phone. Intent dismissIntent = new Intent(NotificationConstants.ACTION_DISMISS); dismissIntent.putExtra(NotificationConstants.KEY_NOTIFICATION_ID, NotificationConstants.NOTIFICATION_ID); PendingIntent pendingIntent = PendingIntent.getService(this, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setDeleteIntent(pendingIntent); //Post the notification. NotificationManagerCompat.from(this).notify(NotificationConstants.NOTIFICATION_ID, builder.build()); }
From source file:com.google.android.apps.muzei.notifications.NewWallpaperNotificationReceiver.java
public static void cancelNotification(Context context) { NotificationManagerCompat nm = NotificationManagerCompat.from(context); nm.cancel(NOTIFICATION_ID); }
From source file:org.chromium.tools.audio_focus_grabber.AudioFocusGrabberListenerService.java
private void showNotification() { RemoteViews view = new RemoteViews(this.getPackageName(), R.layout.audio_focus_grabber_notification_bar); view.setOnClickPendingIntent(R.id.notification_button_gain, createPendingIntent(ACTION_GAIN)); view.setOnClickPendingIntent(R.id.notification_button_transient_pause, createPendingIntent(ACTION_TRANSIENT_PAUSE)); view.setOnClickPendingIntent(R.id.notification_button_transient_duck, createPendingIntent(ACTION_TRANSIENT_DUCK)); view.setOnClickPendingIntent(R.id.notification_button_hide, createPendingIntent(ACTION_HIDE_NOTIFICATION)); NotificationManagerCompat manager = NotificationManagerCompat.from(this); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContent(view) .setSmallIcon(R.drawable.notification_icon); manager.notify(NOTIFICATION_ID, builder.build()); }
From source file:com.tfg.sawan.bsecure.beacon.UriBeaconDiscoveryService.java
private void initialize() { mNotificationManager = NotificationManagerCompat.from(this); mMdnsUrlDiscoverer = new MdnsUrlDiscoverer(this, UriBeaconDiscoveryService.this); mSsdpUrlDiscoverer = new SsdpUrlDiscoverer(this, UriBeaconDiscoveryService.this); mHandler = new Handler(); initializeScreenStateBroadcastReceiver(); }
From source file:com.androidinspain.deskclock.data.TimerModel.java
TimerModel(Context context, SharedPreferences prefs, SettingsModel settingsModel, RingtoneModel ringtoneModel, NotificationModel notificationModel) { mContext = context;/*from ww w . j a va 2s. c o m*/ mPrefs = prefs; mSettingsModel = settingsModel; mRingtoneModel = ringtoneModel; mNotificationModel = notificationModel; mNotificationManager = NotificationManagerCompat.from(context); mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); // Clear caches affected by preferences when preferences change. prefs.registerOnSharedPreferenceChangeListener(mPreferenceListener); // Update timer notification when locale changes. final IntentFilter localeBroadcastFilter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED); mContext.registerReceiver(mLocaleChangedReceiver, localeBroadcastFilter); }
From source file:org.physical_web.physicalweb.UrlDeviceDiscoveryService.java
private void initialize() { mNotificationManager = NotificationManagerCompat.from(this); mUrlDeviceDiscoverers = new ArrayList<>(); if (Utils.isMdnsEnabled(this)) { Log.d(TAG, "mdns started"); mUrlDeviceDiscoverers.add(new MdnsUrlDeviceDiscoverer(this)); }//from w w w. ja va 2s .co m if (Utils.isWifiDirectEnabled(this)) { Log.d(TAG, "wifi direct started"); mUrlDeviceDiscoverers.add(new WifiUrlDeviceDiscoverer(this)); } mUrlDeviceDiscoverers.add(new SsdpUrlDeviceDiscoverer(this)); mUrlDeviceDiscoverers.add(new BleUrlDeviceDiscoverer(this)); for (UrlDeviceDiscoverer urlDeviceDiscoverer : mUrlDeviceDiscoverers) { urlDeviceDiscoverer.setCallback(this); } mUrlDeviceDiscoveryListeners = new ArrayList<>(); mHandler = new Handler(); mPwCollection = new PhysicalWebCollection(); if (!Utils.setPwsEndpoint(this, mPwCollection)) { Utils.warnUserOnMissingApiKey(this); } mCanUpdateNotifications = false; }
From source file:conversandroid.cookingnotifications.MainActivity.java
/** * Notification with an action (opens recipes web page) *///from w ww.ja v a 2s. c o m private void showActionNotification() { int notificationId = 2; // Build an intent for an action to open a url Intent urlIntent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse("http://www.reciperoulette.tv/"); urlIntent.setData(uri); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, urlIntent, 0); //Building notification layout NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.cook).setContentTitle("Cooking tips").setContentText("New recipe available") .setDefaults(Notification.DEFAULT_ALL) //Beware that without some default behaviours //the notification may not show up in the wearable .setAutoCancel(true).setContentIntent(pendingIntent) .addAction(R.mipmap.cook, "Check recipe", pendingIntent); //Creating an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Building the notification and issuing it with the notification manager notificationManager.notify(notificationId, notificationBuilder.build()); }