List of usage examples for android.app Notification PRIORITY_HIGH
int PRIORITY_HIGH
To view the source code for android.app Notification PRIORITY_HIGH.
Click Source Link
From source file:net.olejon.mdapp.MessageIntentService.java
@Override protected void onHandleIntent(Intent intent) { final Context mContext = this; final MyTools mTools = new MyTools(mContext); RequestQueue requestQueue = Volley.newRequestQueue(mContext); int projectVersionCode = mTools.getProjectVersionCode(); String device = mTools.getDevice(); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, getString(R.string.project_website_uri) + "api/1/message/?version_code=" + projectVersionCode + "&device=" + device, new Response.Listener<JSONObject>() { @SuppressLint("InlinedApi") @Override/* w w w. j a v a2s . co m*/ public void onResponse(JSONObject response) { try { final long id = response.getLong("id"); final String title = response.getString("title"); final String message = response.getString("message"); final String bigMessage = response.getString("big_message"); final String button = response.getString("button"); final String uri = response.getString("uri"); final long lastId = mTools.getSharedPreferencesLong("MESSAGE_LAST_ID"); mTools.setSharedPreferencesLong("MESSAGE_LAST_ID", id); if (lastId != 0 && id != lastId) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); NotificationManagerCompat notificationManager = NotificationManagerCompat .from(mContext); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( mContext); notificationBuilder.setWhen(mTools.getCurrentTime()).setAutoCancel(true) .setPriority(Notification.PRIORITY_HIGH) .setVisibility(Notification.VISIBILITY_PUBLIC) .setCategory(Notification.CATEGORY_MESSAGE).setLargeIcon(bitmap) .setSmallIcon(R.drawable.ic_local_hospital_white_24dp) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setLights(Color.BLUE, 1000, 2000).setTicker(message).setContentTitle(title) .setContentText(message) .setStyle(new NotificationCompat.BigTextStyle().bigText(bigMessage)); if (!uri.equals("")) { Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); PendingIntent launchPendingIntent = PendingIntent.getActivity(mContext, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(launchPendingIntent).addAction( R.drawable.ic_local_hospital_white_24dp, button, launchPendingIntent); } notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); } } catch (Exception e) { Log.e("MessageIntentService", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("MessageIntentService", error.toString()); } }); jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonObjectRequest); }
From source file:com.granita.contacticloudsync.syncadapter.AccountSettings.java
@TargetApi(21) protected void showNotification(int id, String title, String message) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder n = new Notification.Builder(context); if (Build.VERSION.SDK_INT >= 16) { n.setPriority(Notification.PRIORITY_HIGH); n.setStyle(new Notification.BigTextStyle().bigText(message)); }//from ww w. j av a2 s. c o m if (Build.VERSION.SDK_INT >= 20) n.setLocalOnly(true); if (Build.VERSION.SDK_INT >= 21) n.setCategory(Notification.CATEGORY_SYSTEM); n.setSmallIcon(R.drawable.ic_launcher); n.setContentTitle(title); n.setContentText(message); nm.notify(id, Build.VERSION.SDK_INT >= 16 ? n.build() : n.getNotification()); }
From source file:net.olejon.mdapp.NotificationsFromSlvIntentService.java
@Override protected void onHandleIntent(Intent intent) { final Context mContext = this; final MyTools mTools = new MyTools(mContext); if (mTools.getDefaultSharedPreferencesBoolean("NOTIFICATIONS_FROM_SLV_NOTIFY") && mTools.isDeviceConnected()) { RequestQueue requestQueue = Volley.newRequestQueue(mContext); int projectVersionCode = mTools.getProjectVersionCode(); String device = mTools.getDevice(); JsonArrayRequest jsonArrayRequest = new JsonArrayRequest( getString(R.string.project_website_uri) + "api/1/notifications-from-slv/?first&version_code=" + projectVersionCode + "&device=" + device, new Response.Listener<JSONArray>() { @SuppressLint("InlinedApi") @Override/* w ww . jav a2 s. c om*/ public void onResponse(JSONArray response) { try { final JSONObject notifications = response.getJSONObject(0); final String title = notifications.getString("title"); final String message = notifications.getString("message"); final String lastTitle = mTools .getSharedPreferencesString("NOTIFICATIONS_FROM_SLV_LAST_TITLE"); if (!title.equals(lastTitle)) { if (!lastTitle.equals("")) { Intent launchIntent = new Intent(mContext, NotificationsFromSlvActivity.class); PendingIntent launchPendingIntent = PendingIntent.getActivity(mContext, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); NotificationManagerCompat notificationManager = NotificationManagerCompat .from(mContext); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( mContext); notificationBuilder.setWhen(mTools.getCurrentTime()) .setPriority(Notification.PRIORITY_HIGH) .setVisibility(Notification.VISIBILITY_PUBLIC) .setCategory(Notification.CATEGORY_MESSAGE).setLargeIcon(bitmap) .setSmallIcon(R.drawable.ic_local_hospital_white_24dp) .setSound(RingtoneManager .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setLights(Color.BLUE, 1000, 2000).setTicker(title) .setContentTitle(title).setContentText(message) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setContentIntent(launchPendingIntent) .addAction(R.drawable.ic_notifications_white_24dp, getString( R.string.service_notifications_from_slv_read_more), launchPendingIntent); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); } mTools.setSharedPreferencesString("NOTIFICATIONS_FROM_SLV_LAST_TITLE", title); } } catch (Exception e) { Log.e("NotificationsFromSlv", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("NotificationsFromSlv", error.toString()); } }); jsonArrayRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonArrayRequest); } }
From source file:com.amlcurran.messages.notifications.UnreadNotificationBuilder.java
Notification buildMultipleSummaryNotification(List<Conversation> conversations, boolean fromNewMessage, CharSequence ticker) {//from w ww. j a v a 2s .c om Time latestMessageTime = MessageAnalyser.getLatestMessageTime(conversations); NotificationCompat.Action markReadAction = actionBuilder.buildMultipleMarkReadAction(conversations); NotificationCompat.Builder defaultBuilder = notificationBuilder.getDefaultBuilder(fromNewMessage); NotificationBinder notificationBinder = new NotificationBinder(defaultBuilder); notificationBinder.setStyle(buildInboxStyle(conversations)); return notificationBinder.getBaseBuilder().addAction(markReadAction).setTicker(ticker) .setGroup(NotificationBuilder.UNREAD_MESSAGES).setPriority(Notification.PRIORITY_HIGH) .setGroupSummary(true).setContentText(styledTextFactory.buildSenderList(conversations)) .setContentTitle(styledTextFactory.buildListSummary(context, conversations)) .setWhen(latestMessageTime.toMillis()).build(); }
From source file:jackpal.androidterm.TermService.java
@Override public void onCreate() { // should really belong to the Application class, but we don't use one... final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs.edit(); String defValue = getDir("HOME", MODE_PRIVATE).getAbsolutePath(); String homePath = prefs.getString("home_path", defValue); editor.putString("home_path", homePath); editor.commit();/* w w w. j a va2 s.c o m*/ compat = new ServiceForegroundCompat(this); mTermSessions = new SessionList(); /* Put the service in the foreground. */ // Define the bounds in which the Activity will be launched into. Intent notifyIntent = new Intent(this, Term.class); notifyIntent.addFlags(NotificationCompat.FLAG_ONGOING_EVENT); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_stat_service_notification_icon); builder.setWhen(System.currentTimeMillis()); Notification simpleNotice = builder.setContentText(getString(R.string.service_notify_text)) .setContentText(getString(R.string.service_notify_text)) .setSmallIcon(R.drawable.ic_stat_service_notification_icon).setContentIntent(pendingIntent) .setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setPriority(Notification.PRIORITY_HIGH) .build(); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, simpleNotice); Log.d(TermDebug.LOG_TAG, "TermService started"); return; }
From source file:com.example.mego.adas.accidents.fcm.ADASFirebaseMessageService.java
/** * Create and show a accident notification containing the received FCM message * * @param longitude accident longitude * @param latitude accident latitude * @param accidentState accident state true if the accident update location , false if new accident * @param title the accident title *//*from w ww .j a v a2 s. c o m*/ private void sendAccidentNotification(Context context, double longitude, double latitude, boolean accidentState, String title) { //Check if new accident or updated one String notificationText = "An accident occurred at longitude: " + longitude + " and latitude: " + latitude; if (accidentState) { notificationText = "An accident location changed to longitude: " + longitude + " and latitude: " + latitude; } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setColor(ContextCompat.getColor(context, R.color.colorPrimary)).setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(NotificationUtils.largeIcon(context)).setContentTitle(title) .setContentText(notificationText) .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText)) .setDefaults(Notification.DEFAULT_VIBRATE).setDefaults(Notification.DEFAULT_SOUND) .setContentIntent(contentIntent(context, longitude, latitude)).setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notificationBuilder.setPriority(Notification.PRIORITY_HIGH); } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(ADAS_ACCIDENT_FCM_NOTIFICATION_ID, notificationBuilder.build()); }
From source file:com.waz.zclient.controllers.notifications.NotificationsController.java
@Override @DebugLog//from w w w . j a v a2 s . c o m public void updateGcmNotification(GcmNotificationsList gcmNotificationsList) { Collection<GcmNotification> gcmNotifications = gcmNotificationsList.getNotifications(); if (gcmNotifications == null || gcmNotifications.size() < 1) { notificationManager.cancel(ZETA_MESSAGE_NOTIFICATION_ID); return; } final Notification notification; if (gcmNotifications.size() == 1) { notification = getSingleMesssageNotification(gcmNotifications); } else { // TODO: Would be nice to show the {@link #getSingleMesssageNotification} as a HeadsUpNotification notification = getMultipleMessagesNotification(gcmNotifications); } if (notification == null) { return; } notification.priority = Notification.PRIORITY_HIGH; notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.deleteIntent = gcmNotificationsList.getClearNotificationsIntent(); attachNotificationLed(notification); attachNotificationSound(gcmNotifications, notification); notificationManager.notify(ZETA_MESSAGE_NOTIFICATION_ID, notification); }
From source file:name.gudong.translate.listener.view.TipViewController.java
public void show(Result result, boolean isShowFavoriteButton, boolean isShowDoneMark, TipView.ITipViewListener mListener) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); boolean isSettingUseSystemNotification = sharedPreferences .getBoolean("preference_show_float_view_use_system", false); if (Utils.isSDKHigh5() && isSettingUseSystemNotification) { StringBuilder sb = new StringBuilder(); for (String string : result.getExplains()) { sb.append(string).append("\n"); }/*from www . ja v a 2 s . com*/ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.icon_notification).setContentTitle(result.getQuery()) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND) .setVibrate(new long[] { 0l }).setPriority(Notification.PRIORITY_HIGH) .setContentText(sb.toString()); /* Add Big View Specific Configuration */ NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // Moves events into the big view for (String string : result.getExplains()) { inboxStyle.addLine(string); } mBuilder.setStyle(inboxStyle); Intent resultIntent = new Intent(mContext, MainActivity.class); resultIntent.putExtra("data", result); PendingIntent resultPendingIntent = PendingIntent.getActivity(mContext, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.addAction(R.drawable.ic_favorite_border_grey_24dp, "?", resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); Notification note = mBuilder.build(); mNotificationManager.notify(result.getQuery().hashCode(), note); } else { TipView tipView = new TipView(mContext); mMapTipView.put(result, tipView); tipView.setListener(mListener); mWindowManager.addView(tipView, getPopViewParams()); tipView.startWithAnim(); tipView.setContent(result, isShowFavoriteButton, isShowDoneMark); closeTipViewCountdown(tipView, mListener); } }
From source file:net.kourlas.voipms_sms.Notifications.java
public void showNotifications(List<String> contacts) { if (!(ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationsActivity)) { Conversation[] conversations = Database.getInstance(applicationContext) .getConversations(preferences.getDid()); for (Conversation conversation : conversations) { if (!conversation.isUnread() || !contacts.contains(conversation.getContact()) || (ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationActivity && ((ConversationActivity) ActivityMonitor.getInstance().getCurrentActivity()) .getContact().equals(conversation.getContact()))) { continue; }/*from w w w . j a v a2 s . c o m*/ String smsContact = Utils.getContactName(applicationContext, conversation.getContact()); if (smsContact == null) { smsContact = Utils.getFormattedPhoneNumber(conversation.getContact()); } String allSmses = ""; String mostRecentSms = ""; boolean initial = true; for (Message message : conversation.getMessages()) { if (message.getType() == Message.Type.INCOMING && message.isUnread()) { if (initial) { allSmses = message.getText(); mostRecentSms = message.getText(); initial = false; } else { allSmses = message.getText() + "\n" + allSmses; } } else { break; } } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(applicationContext); notificationBuilder.setContentTitle(smsContact); notificationBuilder.setContentText(mostRecentSms); notificationBuilder.setSmallIcon(R.drawable.ic_chat_white_24dp); notificationBuilder.setPriority(Notification.PRIORITY_HIGH); notificationBuilder .setSound(Uri.parse(Preferences.getInstance(applicationContext).getNotificationSound())); notificationBuilder.setLights(0xFFAA0000, 1000, 5000); if (Preferences.getInstance(applicationContext).getNotificationVibrateEnabled()) { notificationBuilder.setVibrate(new long[] { 0, 250, 250, 250 }); } else { notificationBuilder.setVibrate(new long[] { 0 }); } notificationBuilder.setColor(0xFFAA0000); notificationBuilder.setAutoCancel(true); notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(allSmses)); Bitmap largeIconBitmap; try { largeIconBitmap = MediaStore.Images.Media.getBitmap(applicationContext.getContentResolver(), Uri.parse(Utils.getContactPhotoUri(applicationContext, conversation.getContact()))); largeIconBitmap = Bitmap.createScaledBitmap(largeIconBitmap, 256, 256, false); largeIconBitmap = Utils.applyCircularMask(largeIconBitmap); notificationBuilder.setLargeIcon(largeIconBitmap); } catch (Exception ignored) { } Intent intent = new Intent(applicationContext, ConversationActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(applicationContext.getString(R.string.conversation_extra_contact), conversation.getContact()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(applicationContext); stackBuilder.addParentStack(ConversationActivity.class); stackBuilder.addNextIntent(intent); notificationBuilder .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT)); Intent replyIntent = new Intent(applicationContext, ConversationQuickReplyActivity.class); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); } else { //noinspection deprecation replyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); } replyIntent.putExtra(applicationContext.getString(R.string.conversation_extra_contact), conversation.getContact()); PendingIntent replyPendingIntent = PendingIntent.getActivity(applicationContext, 0, replyIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action.Builder replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_24dp, applicationContext.getString(R.string.notifications_button_reply), replyPendingIntent); notificationBuilder.addAction(replyAction.build()); Intent markAsReadIntent = new Intent(applicationContext, MarkAsReadReceiver.class); markAsReadIntent.putExtra(applicationContext.getString(R.string.conversation_extra_contact), conversation.getContact()); PendingIntent markAsReadPendingIntent = PendingIntent.getBroadcast(applicationContext, 0, markAsReadIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action.Builder markAsReadAction = new NotificationCompat.Action.Builder( R.drawable.ic_drafts_white_24dp, applicationContext.getString(R.string.notifications_button_mark_read), markAsReadPendingIntent); notificationBuilder.addAction(markAsReadAction.build()); int id; if (notificationIds.get(conversation.getContact()) != null) { id = notificationIds.get(conversation.getContact()); } else { id = notificationIdCount++; notificationIds.put(conversation.getContact(), id); } NotificationManager notificationManager = (NotificationManager) applicationContext .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(id, notificationBuilder.build()); } } }
From source file:com.doomy.padlock.MainActivity.java
private void showNotification() { invalidateOptionsMenu();/*from ww w . j av a2 s . co m*/ String mPort = "5555"; androidDebugBridge(mPort); Intent mIntent = new Intent(this, MainActivity.class); PendingIntent mPendingIntent = PendingIntent.getActivity(this, 0, mIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setContentTitle(getString(R.string.adb_on)) .setContentText(getString(R.string.connect) + " " + getIPAdressWifi() + ":5555") .setSmallIcon(R.drawable.img_adb).setColor(getResources().getColor(R.color.blueGrey)) .setContentIntent(mPendingIntent).setAutoCancel(false).setOngoing(true) .setPriority(Notification.PRIORITY_HIGH); NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotificationManager.notify(0, mBuilder.build()); }