List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:com.appdynamics.demo.gasp.gcm.GCMIntentService.java
/** * Send a notification message that a new update has been received * * @param msg Notification message//from ww w.ja va 2 s. co m */ private void sendNotification(String msg) { NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, LocationsActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("Gasp! Update") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.procasy.dubarah_nocker.gcm.MyGcmPushReceiver.java
/** * Called when message is received.// ww w . j a va 2s . co m * * @param from SenderID of the sender. * @param bundle Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ @Override public void onMessageReceived(String from, Bundle bundle) { MainActivity.getInstance().updateNotification(); try { Log.e("notify_gcm", "success , type = " + bundle.toString()); switch (bundle.getString(GCM_TAG)) { case "GENERAL": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, GENERAL_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } case "HELP": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, HELP_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } JSONObject content = new JSONObject(bundle.getString("content")); JSONObject hr = content.getJSONObject("hr"); JSONArray album = content.getJSONArray("album"); System.out.println(content.getInt("hr_id")); System.out.println(content.toString()); Bundle bundle1 = new Bundle(); bundle1.putString("hr_id", hr.getString("hr_id")); bundle1.putString("hr_user_id", hr.getString("hr_user_id")); bundle1.putString("hr_description", hr.getString("hr_description")); bundle1.putString("hr_est_date", hr.getString("hr_est_date")); bundle1.putString("hr_est_time", hr.getString("hr_est_time")); bundle1.putString("hr_skill_id", hr.getString("hr_skill_id")); bundle1.putString("hr_ua_id", hr.getString("hr_ua_id")); bundle1.putString("hr_voice_record", hr.getString("hr_voice_record")); bundle1.putString("hr_language", hr.getString("hr_language")); bundle1.putString("hr_lat", hr.getString("hr_lat")); bundle1.putString("hr_lon", hr.getString("hr_lon")); bundle1.putString("hr_address", hr.getString("hr_address")); ArrayList<String> array = new ArrayList<>(); for (int i = 0; i < album.length(); i++) { JSONObject object = album.getJSONObject(i); array.add(object.getString("ahr_img")); } bundle1.putStringArrayList("album", array); Intent intent = (new Intent(getApplicationContext(), JobRequestActivity.class)); intent.putExtras(bundle1); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplicationContext().startActivity(intent); break; } case "APPOINTEMENT": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, APPOINTEMENT_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } case "QOUTA_USER": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, USER_Qouta_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } case "QOUTA_NOCKER": { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG)) .setContentText(bundle.getString(DESC_TAG)); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext()); mNotification.open(); try { ContentValues contentValues = new ContentValues(); contentValues.put(mNotification.COL_notification_type, Nocker_Qouta_TAG); contentValues.put(mNotification.COL_notfication_status, 0); contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG)); contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG)); contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG)); mNotification.insertEntry(contentValues); } catch (Exception e) { e.printStackTrace(); } finally { mNotification.close(); } break; } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.android.settings.aokpstats.ReportingService.java
private void promptUser() { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent nI = new Intent(); nI.setComponent(new ComponentName(getPackageName(), Settings.AnonymousStatsActivity.class.getName())); PendingIntent pI = PendingIntent.getActivity(this, 0, nI, 0); Notification.Builder builder = new Notification.Builder(this).setSmallIcon(R.drawable.ic_aokp_stats_notif) .setAutoCancel(true).setTicker(getString(R.string.anonymous_statistics_title)).setContentIntent(pI) .setWhen(0).setContentTitle(getString(R.string.anonymous_statistics_title)) .setContentText(getString(R.string.anonymous_notification_desc)); nm.notify(1, builder.getNotification()); }
From source file:com.samknows.measurement.test.TestExecutor.java
@SuppressWarnings("deprecation") public void showNotification(String message) { String title = tc.getString(R.string.ntf_title); NotificationManager manager = (NotificationManager) tc.getSystemService(Context.NOTIFICATION_SERVICE); Notification n = new Notification(R.drawable.icon, message, System.currentTimeMillis()); PendingIntent intent = PendingIntent.getService(tc.getServiceContext(), Constants.RC_NOTIFICATION, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT); n.setLatestEventInfo(tc.getServiceContext(), title, message, intent); manager.notify(Constants.NOTIFICATION_ID, n); }
From source file:com.example.ramap.MainActivity.java
@SuppressWarnings("deprecation") private void Notify(String notificationTitle, String notificationMessage) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); @SuppressWarnings("deprecation") Notification notification = new Notification(R.drawable.ic_check_in, "New Check In", System.currentTimeMillis()); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(MainActivity.this, notificationTitle, notificationMessage, pendingIntent); notificationManager.notify(9999, notification); }
From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java
private void buildPushNotification(Context context, Intent intent, PushDataInfo dataInfo) { String title = dataInfo.getTitle(); String body = dataInfo.getAlert(); String message = dataInfo.getPushDataString(); Builder builder = new Builder(context); builder.setAutoCancel(true);/* w w w.java 2 s . c om*/ builder.setContentTitle(title); // builder.setContentText(body); // builder.setTicker(body); // ?? String[] remindType = dataInfo.getRemindType(); if (remindType != null) { if (remindType.length == 3) { builder.setDefaults(Notification.DEFAULT_ALL); } else { int defaults = 0; for (int i = 0; i < remindType.length; i++) { if ("sound".equalsIgnoreCase(remindType[i])) { defaults = Notification.DEFAULT_SOUND; continue; } if ("shake".equalsIgnoreCase(remindType[i])) { defaults = defaults | Notification.DEFAULT_VIBRATE; continue; } if ("breathe".equalsIgnoreCase(remindType[i])) { defaults = defaults | Notification.DEFAULT_LIGHTS; continue; } } builder.setDefaults(defaults); } } Resources res = context.getResources(); int icon = res.getIdentifier("icon", "drawable", intent.getPackage()); builder.setSmallIcon(icon); builder.setWhen(System.currentTimeMillis()); // String iconUrl = dataInfo.getIconUrl(); boolean isDefaultIcon = !TextUtils.isEmpty(iconUrl) && "default".equalsIgnoreCase(iconUrl); Bitmap bitmap = null; if (!isDefaultIcon) { bitmap = getIconBitmap(context, iconUrl); } String fontColor = dataInfo.getFontColor(); RemoteViews remoteViews = null; if (!TextUtils.isEmpty(fontColor)) { int color = BUtility.parseColor(fontColor); int alphaColor = parseAlphaColor(fontColor); remoteViews = new RemoteViews(intent.getPackage(), EUExUtil.getResLayoutID("push_notification_view")); // Title remoteViews.setTextViewText(EUExUtil.getResIdID("notification_title"), title); remoteViews.setTextColor(EUExUtil.getResIdID("notification_title"), color); // Body remoteViews.setTextViewText(EUExUtil.getResIdID("notification_body"), body); remoteViews.setTextColor(EUExUtil.getResIdID("notification_body"), alphaColor); // LargeIcon if (bitmap != null) { remoteViews.setImageViewBitmap(EUExUtil.getResIdID("notification_largeIcon"), bitmap); } else { remoteViews.setImageViewResource(EUExUtil.getResIdID("notification_largeIcon"), EUExUtil.getResDrawableID("icon")); } // Time SimpleDateFormat format = new SimpleDateFormat("HH:mm"); remoteViews.setTextViewText(EUExUtil.getResIdID("notification_time"), format.format(System.currentTimeMillis())); remoteViews.setTextColor(EUExUtil.getResIdID("notification_time"), alphaColor); builder.setContent(remoteViews); } Intent notiIntent = new Intent(context, EBrowserActivity.class); notiIntent.putExtra("ntype", F_TYPE_PUSH); notiIntent.putExtra("data", body); notiIntent.putExtra("message", message); Bundle bundle = new Bundle(); bundle.putSerializable(PushReportConstants.PUSH_DATA_INFO_KEY, dataInfo); notiIntent.putExtras(bundle); PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationNB, notiIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = builder.build(); // Android v4bug2.3?Builder?NotificationRemoteView?? if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && remoteViews != null) { notification.contentView = remoteViews; } manager.notify(notificationNB, notification); notificationNB++; }
From source file:androidx.navigation.testapp.AndroidFragment.java
@Override public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); TextView tv = view.findViewById(R.id.text); tv.setText(getArguments().getString("myarg")); Button b = view.findViewById(R.id.send_notification); b.setOnClickListener(new View.OnClickListener() { @Override//from w ww. j a va 2 s . c o m public void onClick(View v) { EditText editArgs = view.findViewById(R.id.edit_args); Bundle args = new Bundle(); args.putString("myarg", editArgs.getText().toString()); PendingIntent deeplink = Navigation.findNavController(v).createDeepLink() .setDestination(R.id.android).setArguments(args).createPendingIntent(); NotificationManager notificationManager = (NotificationManager) requireContext() .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { notificationManager.createNotificationChannel( new NotificationChannel("deeplink", "Deep Links", NotificationManager.IMPORTANCE_HIGH)); } NotificationCompat.Builder builder = new NotificationCompat.Builder(requireContext(), "deeplink") .setContentTitle("Navigation").setContentText("Deep link to Android") .setSmallIcon(R.drawable.ic_android).setContentIntent(deeplink).setAutoCancel(true); notificationManager.notify(0, builder.build()); } }); }
From source file:com.QuarkLabs.BTCeClient.services.CheckTickersService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sh = PreferenceManager.getDefaultSharedPreferences(this); Set<String> x = sh.getStringSet("PairsToDisplay", new HashSet<String>()); if (x.size() == 0) { return;/* ww w. j a v a 2 s . c o m*/ } String[] pairs = x.toArray(new String[x.size()]); ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); String url = BASE_URL; for (String xx : pairs) { url += xx.replace("/", "_").toLowerCase(Locale.US) + "-"; } SimpleRequest reqSim = new SimpleRequest(); if (networkInfo != null && networkInfo.isConnected()) { JSONObject data = null; try { data = reqSim.makeRequest(url); } catch (JSONException e) { e.printStackTrace(); } if (data != null && data.optInt("success", 1) != 0) { ArrayList<Ticker> tickers = new ArrayList<>(); for (@SuppressWarnings("unchecked") Iterator<String> iterator = data.keys(); iterator.hasNext();) { String key = iterator.next(); JSONObject pairData = data.optJSONObject(key); Ticker ticker = new Ticker(key); ticker.setUpdated(pairData.optLong("updated")); ticker.setAvg(pairData.optDouble("avg")); ticker.setBuy(pairData.optDouble("buy")); ticker.setSell(pairData.optDouble("sell")); ticker.setHigh(pairData.optDouble("high")); ticker.setLast(pairData.optDouble("last")); ticker.setLow(pairData.optDouble("low")); ticker.setVol(pairData.optDouble("vol")); ticker.setVolCur(pairData.optDouble("vol_cur")); tickers.add(ticker); } String message = checkNotifiers(tickers, TickersStorage.loadLatestData()); if (message.length() != 0) { NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); NotificationCompat.Builder nb = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)) .setSmallIcon(R.drawable.ic_stat_bitcoin_sign) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentText(message.substring(0, message.length() - 2)); notificationManager.notify(ConstantHolder.ALARM_NOTIF_ID, nb.build()); } Map<String, Ticker> newData = new HashMap<>(); for (Ticker ticker : tickers) { newData.put(ticker.getPair(), ticker); } TickersStorage.saveData(newData); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("UpdateTickers")); } } else { new Handler().post(new Runnable() { @Override public void run() { //Toast.makeText(CheckTickersService.this, "Unable to fetch data", Toast.LENGTH_SHORT).show(); } }); } }
From source file:fr.ardeconnect.proxy.Service.java
private void showNotification(boolean bProtect) { Logd(TAG, "show protected icon " + bProtect); // this is it, we'll build the notification! // in the addAction method, if you don't want any icon, just set the first param to 0 Notification mNotification = null; if (bProtect) { mNotification = new Notification.Builder(this) .setContentTitle("ARDECO PROXY").setContentText("idle").setSmallIcon(R.drawable.ardeco_off) .setAutoCancel(false).build(); } else {/*from w ww. j a va 2s. com*/ mNotification = new Notification.Builder(this) .setContentTitle("ARDECO PROXY").setContentText("active").setSmallIcon(R.drawable.ardeco_on) .setAutoCancel(false).build(); } // to make it non clearable mNotification.flags |= Notification.FLAG_NO_CLEAR; NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // If you want to hide the notification after it was selected, do the code below // myNotification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, mNotification); }
From source file:com.github.rutvijkumar.twittfuse.services.OfflinePostedTweetProcessingService.java
private void sendNotification(Tweet newTweet) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent intent = new Intent(this, TimeLineActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); int random_int = new Random().nextInt(); // build notification // the addAction re-use the same intent to keep the example short Notification n = new Notification.Builder(this).setContentTitle("Tweet posted successfully") .setContentText(newTweet.getBody()).setSmallIcon(R.drawable.ic_launcher).setContentIntent(pIntent) .setAutoCancel(true).setStyle(new Notification.BigTextStyle().bigText(newTweet.getBody())).build(); notificationManager.notify(random_int, n); }