List of usage examples for android.app Notification DEFAULT_SOUND
int DEFAULT_SOUND
To view the source code for android.app Notification DEFAULT_SOUND.
Click Source Link
From source file:com.rickendirk.rsgwijzigingen.ZoekService.java
private void sendNotification(Wijzigingen wijzigingen) { boolean isFoutMelding = wijzigingen.isFoutmelding(); boolean isVerbindFout; boolean isNieuw; //Tot tegendeel bewezen is if (isFoutMelding) { isVerbindFout = wijzigingen.isVerbindfout(); isNieuw = false;/*from w w w . j av a 2 s . c o m*/ } else { isVerbindFout = false; isNieuw = wijzigingen.isNieuw(this); } if (!isFoutMelding) { wijzigingen.saveToSP(this); } if (!isFoutMelding && !isNieuw) { Log.i(TAG, "Geen nieuwe wijzigingen, geen notificatie"); return; } NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_rsg_notific).setContentTitle("Roosterwijzigingen") .setColor(getResources().getColor(R.color.lighter_blue)) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS); if (isFoutMelding) { if (isVerbindFout) { Log.i(TAG, "Er was geen internetverbinding bij het zoeken"); boolean moetHerhalen = PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("pref_auto_herhaal_geenInternet", false); if (moetHerhalen) { setAlarmIn20Min(); Log.i(TAG, "Zal ivm geen internet in 20 minuten opnieuw zoeken"); return; } else { builder.setContentText("Er was geen internetverbinding. Probeer het handmatig opnieuw"); } } else { builder.setContentText("Er was een fout. Probeer het handmatig opnieuw"); } } else { boolean zijnWijzigingen = wijzigingen.zijnWijzigingen; ArrayList<String> wijzigingenList = wijzigingen.getWijzigingen(); addPossibleMessage(wijzigingen, wijzigingenList); if (zijnWijzigingen) { if (wijzigingenList.size() == 1) { builder.setContentText(wijzigingenList.get(0)); } else { builder.setContentText("Er zijn " + wijzigingenList.size() + " wijzigingen!"); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle("De roosterwijzigingen zijn:"); for (int i = 0; i < wijzigingenList.size(); i++) { inboxStyle.addLine(wijzigingenList.get(i)); } builder.setStyle(inboxStyle); } } else { boolean alleenBijWijziging = PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("pref_auto_zoek_alleenBijWijziging", true); if (!alleenBijWijziging) { //Dus ook bij geen-wijzigingen builder.setContentText("Er zijn geen roosterwijzigingen"); } else return; } } Intent resultIntent = new Intent(this, MainActivity.class); resultIntent.putExtra("isVanNotificatie", true); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(pendingIntent); NotificationManagerCompat notifManager = NotificationManagerCompat.from(this); notifManager.notify(notifID, builder.build()); vibrate(); Log.i(TAG, "Nieuwe notificatie gemaakt"); }
From source file:com.mowares.massagerexpressclient.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from ww w .j ava2 s . c o m*/ private void generateNotification(Context context, String message) { // System.out.println("this is message " + message); // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message); int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainDrawerActivity.class); notificationIntent.putExtra("fromNotification", "notification"); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); //notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; System.out.println("notification====>" + message); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; // notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0x00000000; notification.ledOnMS = 0; notification.ledOffMS = 0; notificationManager.notify(0, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock"); wakeLock.acquire(); wakeLock.release(); }
From source file:com.google.android.apps.chrometophone.C2DMReceiver.java
private void generateNotification(Context context, String msg, String title, Intent intent) { int icon = R.drawable.status_icon; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, title, when); notification.setLatestEventInfo(context, title, msg, PendingIntent.getActivity(context, 0, intent, 0)); notification.defaults = Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_AUTO_CANCEL; SharedPreferences settings = Prefs.get(context); int notificatonID = settings.getInt("notificationID", 0); // allow multiple notifications NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(notificatonID, notification); SharedPreferences.Editor editor = settings.edit(); editor.putInt("notificationID", ++notificatonID % 32); editor.commit();/* ww w. jav a2 s . c o m*/ }
From source file:com.cloverstudio.spika.GCMIntentService.java
@SuppressWarnings("deprecation") public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras) { if (fromName != null) { final NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE);/*from w w w.j ava 2 s .c o m*/ Notification notification = new Notification(R.drawable.icon_notification, message, System.currentTimeMillis()); notification.number = mNotificationCounter + 1; mNotificationCounter = mNotificationCounter + 1; Intent intent = new Intent(this, SplashScreenActivity.class); intent.replaceExtras(pushExtras); intent.putExtra(Const.PUSH_INTENT, true); intent.setAction(Long.toString(System.currentTimeMillis())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, context.getString(R.string.app_name), message, pendingIntent); notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_AUTO_CANCEL; String notificationId = Double.toString(Math.random()); notificationManager.notify(notificationId, 0, notification); } }
From source file:realizer.com.schoolgenieparent.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. */// w w w .ja v a2 s . c o m private static void generateNotification(Context context, String message) { DatabaseQueries qr = new DatabaseQueries(context); Calendar calendar = Calendar.getInstance(); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); String date = df.format(calendar.getTime()); int icon = R.mipmap.ic_launcher; String[] msg = message.split("@@@"); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); Log.d("Feature Type=", msg[0]); if (msg[0].equals("GroupConversation")) { Bundle b = new Bundle(); String studid = sharedpreferences.getString("UidName", ""); if (msg[6].equals(studid)) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); Log.d("Message=", message); Notification notification; NotificationCompat.Builder builder = new NotificationCompat.Builder(context); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, DrawerActivity.class); //// notificationIntent.putExtra("FragName","Chat"); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); SharedPreferences.Editor edit = sharedpreferences.edit(); edit.putString("FragName", "Chat"); edit.commit(); PendingIntent intent = PendingIntent.getActivity(context, notificatinViewStarID, notificationIntent, 0); int num = ++numStarMessages; builder.setAutoCancel(true); builder.setContentTitle("Chat"); if (num == 1) { builder.setContentText(msg[6]); } else { builder.setContentText("You have received " + num + " Messages."); } builder.setSmallIcon(icon); builder.setContentIntent(intent); builder.setOngoing(false); //API level 16 builder.setNumber(num); builder.setDefaults(Notification.DEFAULT_SOUND); builder.setDefaults(Notification.DEFAULT_VIBRATE); builder.build(); notification = builder.getNotification(); notificationManager.notify(notificatinViewStarID, notification); DatabaseQueries qr1 = new DatabaseQueries(context); edit.putString("ReceiverId", msg[2]); edit.putString("ReceiverName", msg[3]); edit.putString("ReceiverUrl", msg[5]); b.putString("ReceiverId", msg[2]); b.putString("ReceiverName", msg[3]); b.putString("ReceiverUrl", msg[5]); String std = sharedpreferences.getString("SyncStd", ""); String div = sharedpreferences.getString("SyncDiv", ""); SimpleDateFormat df1 = new SimpleDateFormat("dd/MM/yyyy kk:mm:ss"); String date1 = df1.format(calendar.getTime()); Date sendDate = new Date(); try { sendDate = df.parse(date1); } catch (ParseException e) { e.printStackTrace(); } ArrayList<TeacherQuerySendModel> allChat = qr.GetQueuryData(msg[2]); boolean isPresentNot = false; for (int i = 0; i < allChat.size(); i++) { if (allChat.get(i).getText().equals(msg[4])) { isPresentNot = true; break; } else { isPresentNot = false; } } long n = 0; if (!isPresentNot) { n = qr1.insertQuery(msg[1], msg[2], msg[3], msg[6], msg[4], msg[5], date1, "true", sendDate); if (n >= 0) { ArrayList<TeacherQuery1model> temp = qr.GetInitiatedChat("true"); boolean isPresent = false; for (int i = 0; i < temp.size(); i++) { if (temp.get(i).getUid().equals(msg[2])) { isPresent = true; break; } } int unread = qr1.GetUnreadCount(msg[2]); if (isPresent) { qr1.updateInitiatechat(std, div, msg[3], "true", msg[2], unread + 1, msg[5]); } else { long m = 0; m = qr1.insertInitiatechat(msg[3], "true", msg[2], 0, msg[5]); if (m > 0) Log.d("Group Conversation", " Done!!!"); else Log.d("Group Conversation", "Not Done!!!"); } if (n > 0) { NotificationModel obj = qr.GetNotificationByUserId(msg[2]); if (obj.getId() == 0) { n = 0; NotificationModel notification1 = new NotificationModel(); notification1.setNotificationId(9); notification1.setNotificationDate(date); notification1.setNotificationtype("Message"); notification1.setMessage(msg[4]); notification1.setIsRead("false"); notification1.setAdditionalData2(msg[3]); notification1.setAdditionalData1(msg[5] + "@@@" + (unread + 1)); n = qr.InsertNotification(notification1); if (Singleton.getResultReceiver() != null) Singleton.getResultReceiver().send(1, null); } else { n = 0; obj.setMessage(msg[4]); obj.setNotificationDate(date); obj.setAdditionalData1(msg[5] + "@@@" + (unread + 1)); n = qr.UpdateNotification(obj); Bundle b1 = new Bundle(); b1.putInt("NotificationId", 1); b1.putString("NotificationDate", date); b1.putString("NotificationType", "Query"); b1.putString("NotificationMessage", msg[4]); b1.putString("IsNotificationread", "false"); b1.putString("AdditionalData1", msg[5] + "@@@" + (unread + 1)); b1.putString("AdditionalData2", msg[3]); if (Singleton.getResultReceiver() != null) Singleton.getResultReceiver().send(1, b); } } Log.d("Conversation", " Done!!!"); } else { Log.d("Conversation", " Not Done!!!"); } } } Singleton obj = Singleton.getInstance(); if (obj.getResultReceiver() != null) { obj.getResultReceiver().send(100, b); } } }
From source file:com.codename1.impl.android.LocalNotificationPublisher.java
private Notification createAndroidNotification(Context context, LocalNotification localNotif, PendingIntent content) {//from w ww . ja va 2s . c om Context ctx = context; int smallIcon = ctx.getResources().getIdentifier("ic_stat_notify", "drawable", ctx.getApplicationInfo().packageName); int icon = ctx.getResources().getIdentifier("icon", "drawable", ctx.getApplicationInfo().packageName); if (smallIcon == 0) { smallIcon = icon; } else { icon = smallIcon; } NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx); builder.setContentTitle(localNotif.getAlertTitle()); builder.setContentText(localNotif.getAlertBody()); builder.setAutoCancel(true); if (localNotif.getBadgeNumber() >= 0) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) { builder.setNumber(localNotif.getBadgeNumber()); } } String image = localNotif.getAlertImage(); if (image != null && image.length() > 0) { if (image.startsWith("/")) { image = image.substring(1); } InputStream in; try { in = context.getAssets().open(image); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap im = BitmapFactory.decodeStream(in, null, opts); builder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(im)); } catch (IOException ex) { Logger.getLogger(LocalNotificationPublisher.class.getName()).log(Level.SEVERE, null, ex); } } builder.setSmallIcon(smallIcon); builder.setContentIntent(content); AndroidImplementation.setNotificationChannel( (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE), builder, context); String sound = localNotif.getAlertSound(); if (sound != null && sound.length() > 0) { sound = sound.toLowerCase(); builder.setSound(android.net.Uri.parse("android.resource://" + ctx.getApplicationInfo().packageName + "/raw" + sound.substring(0, sound.indexOf(".")))); } Notification n = builder.build(); n.icon = icon; if (sound == null || sound.length() == 0) { n.defaults |= Notification.DEFAULT_SOUND; } return n; }
From source file:com.androzic.plugin.tracker.SMSReceiver.java
@Override public void onReceive(Context context, Intent intent) { String Sender = ""; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Log.e(TAG, "SMS received"); Bundle extras = intent.getExtras();/*from w ww . j a v a 2s .co m*/ if (extras == null) return; StringBuilder messageBuilder = new StringBuilder(); Object[] pdus = (Object[]) extras.get("pdus"); for (int i = 0; i < pdus.length; i++) { SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]); String text = msg.getMessageBody(); Sender = msg.getDisplayOriginatingAddress(); Log.w(TAG, "Sender: " + Sender); if (text == null) continue; messageBuilder.append(text); } String text = messageBuilder.toString(); boolean flexMode = prefs.getBoolean(context.getString(R.string.pref_tracker_use_flex_mode), context.getResources().getBoolean(R.bool.def_flex_mode)); Log.i(TAG, "SMS: " + text); Tracker tracker = new Tracker(); if (!parseXexunTK102(text, tracker) && !parseJointechJT600(text, tracker) && !parseTK102Clone1(text, tracker) && !(parseFlexMode(text, tracker) && flexMode)) return; if (tracker.message != null) { tracker.message = tracker.message.trim(); if ("".equals(tracker.message)) tracker.message = null; } tracker.sender = Sender; if (!"".equals(tracker.sender)) { // Save tracker data TrackerDataAccess dataAccess = new TrackerDataAccess(context); dataAccess.updateTracker(tracker); try { Application application = Application.getApplication(); tracker = dataAccess.getTracker(tracker.sender);//get latest positon of tracker application.sendTrackerOnMap(dataAccess, tracker); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } dataAccess.close(); context.sendBroadcast(new Intent(Application.TRACKER_DATE_RECEIVED_BROADCAST)); // Show notification boolean notifications = prefs.getBoolean(context.getString(R.string.pref_tracker_notifications), context.getResources().getBoolean(R.bool.def_notifications)); if (notifications) { Intent i = new Intent("com.androzic.COORDINATES_RECEIVED"); i.putExtra("title", tracker.message != null ? tracker.message : tracker.name); i.putExtra("sender", tracker.name); i.putExtra("origin", context.getApplicationContext().getPackageName()); i.putExtra("lat", tracker.latitude); i.putExtra("lon", tracker.longitude); String msg = context.getString(R.string.notif_text, tracker.name); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle(context.getString(R.string.app_name)); if (tracker.message != null) builder.setContentText(tracker.name + ": " + tracker.message); else builder.setContentText(msg); PendingIntent contentIntent = PendingIntent.getBroadcast(context, (int) tracker._id, i, PendingIntent.FLAG_ONE_SHOT); builder.setContentIntent(contentIntent); builder.setSmallIcon(R.drawable.ic_stat_tracker); builder.setTicker(msg); builder.setWhen(tracker.time); int defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND; boolean vibrate = prefs.getBoolean(context.getString(R.string.pref_tracker_vibrate), context.getResources().getBoolean(R.bool.def_vibrate)); if (vibrate) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); builder.setAutoCancel(true); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int) tracker._id, notification); } // Conceal SMS boolean concealsms = prefs.getBoolean(context.getString(R.string.pref_tracker_concealsms), context.getResources().getBoolean(R.bool.def_concealsms)); if (concealsms) abortBroadcast(); } }
From source file:edu.oakland.cse480.GCMIntentService.java
public void sendCustNotification(String incomingMsg) { Log.i("incomingMsg = ", "" + incomingMsg); int msgCode;/* www.j a v a 2s.c om*/ try { msgCode = Character.getNumericValue(incomingMsg.charAt(0)); } catch (Exception e) { msgCode = 0; } String msg; //String[] separated = incomingMsg.split("|"); //separated[0] = separated[0]; //discard //separated[1] = separated[1] + ""; //separated[2] = separated[2] + ""; //Additional message with "" to negate a null boolean showNotification = true; Intent intent; switch (msgCode) { case 1: msg = "A new player joined the game"; intent = new Intent("UpdateGameLobby"); intent.putExtra("GAMESTARTED", false); this.sendBroadcast(intent); break; case 2: msg = "The game has started"; intent = new Intent("UpdateGameLobby"); intent.putExtra("GAMESTARTED", true); this.sendBroadcast(intent); break; case 3: msg = "It is your turn to bet"; intent = new Intent("UpdateGamePlay"); this.sendBroadcast(intent); //Stuff break; case 4: msg = "Flop goes"; break; case 5: msg = "A card has been dealt"; //Stuff break; case 6: msg = "The river card, has been dealt"; //Stuff break; case 7: msg = "Hand is over. Winner was " + incomingMsg.substring(1); intent = new Intent("UpdateGamePlay"); intent.putExtra("WINNER", "Winner of last hand: " + incomingMsg.substring(1)); this.sendBroadcast(intent); //Stuff break; case 8: msg = "Game is over. Winner was " + incomingMsg.substring(1); intent = new Intent("UpdateGamePlay"); intent.putExtra("WINNER", "Winner of Game: " + incomingMsg.substring(1)); this.sendBroadcast(intent); //Stuff break; default: msg = "Switch case isn't working"; showNotification = false; //Some default stuff break; } if (showNotification) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent newIntent = new Intent(this, Gameplay.class); newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, newIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Poker Notification") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); Notification notification = mBuilder.build(); notification.defaults |= Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE; notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS; mNotificationManager.notify(NOTIFICATION_ID, notification); } }
From source file:com.piggate.sdk.Piggate.java
public void postNotification(String title, String msg, Class myClass, int resource, Bundle extras, Boolean force) {//from w w w .ja va 2 s. co m if (!getApplicationContext().getPackageName() .equalsIgnoreCase(((ActivityManager) getApplicationContext() .getSystemService(getApplicationContext().ACTIVITY_SERVICE)).getRunningAppProcesses() .get(0).processName) || force) { Intent notifyIntent = new Intent(_context, myClass); if (extras != null) notifyIntent.putExtras(extras); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivities(_context, 0, new Intent[] { notifyIntent }, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new Notification.Builder(_context).setSmallIcon(resource) .setContentTitle(title).setContentText(msg).setAutoCancel(true).setContentIntent(pendingIntent) .build(); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_LIGHTS; notificationManager.notify(123, notification); } }
From source file:com.ta.truckmap.gpstracking.GcmIntentService.java
@SuppressWarnings("deprecation") private Notification createNotificationConstraints(PendingIntent contentIntent, int type) { Notification notification = new Notification(R.drawable.appicon, TAG, System.currentTimeMillis()); notification.setLatestEventInfo(this, getResources().getString(R.string.app_name), myMsg, contentIntent); notification.defaults |= Notification.DEFAULT_SOUND; long[] vibrate = { 0, 100, 200, 300 }; notification.vibrate = vibrate;/*w w w.j av a2 s .c om*/ notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_AUTO_CANCEL; return notification; }