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.arifin.taxi.penumpang.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. */// w ww.ja va 2 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); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); notification = builder.setContentIntent(intent).setSmallIcon(icon).setTicker(message).setWhen(when) .setAutoCancel(true).setContentTitle(title).setContentText(message).build(); // mNM.notify(NOTIFICATION, notification); /*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.example.xyzreader.cp0.ArticleListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.refresh) { DummyContent.DummyItem dummy = DummyContent.ITEMS.get(0); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 16;//from w w w .j a v a2 s. c om Bitmap photo = BitmapFactory.decodeResource(getResources(), dummy.photoResId); Notification n = new NotificationCompat.Builder(getActivity()).setContentTitle("Article published") .setSmallIcon(R.drawable.stat_icon).setDefaults(Notification.DEFAULT_SOUND).setLargeIcon(photo) .setStyle( new NotificationCompat.BigPictureStyle().bigPicture(photo).setSummaryText(dummy.title)) .setContentText(dummy.title) .setContentIntent(PendingIntent.getActivity(getActivity(), 0, new Intent(getActivity(), getActivity().getClass()), PendingIntent.FLAG_UPDATE_CURRENT)) .setAutoCancel(true) .addAction(R.drawable.ic_share, "Share", PendingIntent.getActivity(getActivity(), 0, new Intent(getActivity(), getActivity().getClass()), PendingIntent.FLAG_UPDATE_CURRENT)) .build(); NotificationManager nm = (NotificationManager) getActivity() .getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(1, n); return true; } return super.onOptionsItemSelected(item); }
From source file:dentex.youtube.downloader.utils.Utils.java
public static void setNotificationDefaults(NotificationCompat.Builder aBuilder) { String def = YTD.settings.getString("notification_defaults", "0"); if (aBuilder != null) { if (def.equals("0")) { aBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); }/* w w w.j av a 2 s. com*/ if (def.equals("1")) { aBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS); } if (def.equals("2")) { aBuilder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); } if (def.equals("3")) { aBuilder.setDefaults(Notification.DEFAULT_ALL); } if (def.equals("4")) { aBuilder.setDefaults(Notification.DEFAULT_SOUND); } if (def.equals("5")) { aBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (def.equals("6")) { aBuilder.setDefaults(Notification.DEFAULT_LIGHTS); } if (def.equals("7")) { // nothing... } } }
From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java
private void notify(Context context, boolean isConnectedPower, boolean hasVibration, boolean hasSound, int notifyCount) { final Resources res = context.getResources(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notify).setContentTitle(res.getString(R.string.notify_content_title)) .setAutoCancel(true);/*from ww w .ja v a2 s . c o m*/ if (notifyCount == 1) { final int resContentTextSingle = (isConnectedPower ? R.string.notify_content_text_single_on : R.string.notify_content_text_single_off); mBuilder.setContentText(res.getString(resContentTextSingle)); } else { mBuilder.setNumber(notifyCount).setContentText(res.getString(R.string.notify_content_text_multi)); } if (hasVibration && hasSound) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND); } else if (hasVibration) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } else if (hasSound) { mBuilder.setDefaults(Notification.DEFAULT_SOUND); } // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MainActivity.class); final Bundle extras = new Bundle(); extras.putBoolean(Const.IntentExtras.INCREMENT_NOTIFY_GROUP, true); extras.putBoolean(Const.IntentExtras.RESET_NOTIFY_NUMBER, true); resultIntent.putExtras(extras); resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); mBuilder.setContentIntent( PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT)); Intent receiverIntent = new Intent(context, PowerConnectionReceiver.class); receiverIntent.setAction(Const.IntentActions.NOTIFY_DELETE); PendingIntent deleteIntent = PendingIntent.getBroadcast(context, Const.RequestCodes.RESET_NOTIFY_NUMBER, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setDeleteIntent(deleteIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // NOTIFY_ID allows updates to the notification later on. mNotificationManager.notify(Const.NOTIFY_ID, mBuilder.build()); }
From source file:vn.seasoft.sachcuatui.GCMService.GCMIntentService.java
private void sendNotification(String msg, Book book) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent;/* w w w. j a v a2 s .co m*/ if (book == null) { intent = new Intent(this, MainActivity.class); } else { intent = new Intent(this, actInfoBook.class); intent.putExtra("idbook", book.getIdbook()); intent.putExtra("titlebook", book.getTitle()); intent.putExtra("authorbook", book.getAuthor()); intent.putExtra("countview", book.getCountview()); intent.putExtra("countdownload", book.getCountdownload()); intent.putExtra("idcategory", book.getIdcategory()); intent.putExtra("summary", book.getSummary()); intent.putExtra("cover", book.getImagecover()); } intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Sch Ca Tui") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setAutoCancel(true); mBuilder.setContentIntent(contentIntent); Notification notification = mBuilder.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_LIGHTS; mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:tw.com.ksmt.cloud.libs.Utils.java
public static void generateNotification(Context context, String title, String message) { if (!PrjCfg.NOTIFICATION.equals("true")) { return;//from w w w. jav a2 s. c o m } int icon; if (PrjCfg.CUSTOMER.equals(PrjCfg.CUSTOMER_FULLKEY)) { icon = R.mipmap.ic_launcher_fullkey; title = (title == null) ? context.getString(R.string.app_name_fullkey) : title; } else { icon = R.mipmap.ic_launcher; title = (title == null) ? context.getString(R.string.app_name) : title; } long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notification = new NotificationCompat.Builder(context).setSmallIcon(icon) .setContentText(message).setWhen(when); Intent notificationIntent; if (message.equals(context.getString(R.string.received_new_announce))) { notificationIntent = new Intent(context, AnnounceActivity.class); } else { notificationIntent = new Intent(context, NotificationActivity.class); } // 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, 0); notification.setContentTitle(title); notification.setContentIntent(intent); notification.setAutoCancel(true); if (PrjCfg.NOTIFICATION_SOUND.equals("true")) { notification.setDefaults(Notification.DEFAULT_SOUND); if (PrjCfg.NOTIFICATION_VIBRATION.equals("true")) { notification.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); } } if (PrjCfg.NOTIFICATION_VIBRATION.equals("true")) { notification.setDefaults(Notification.DEFAULT_VIBRATE); if (PrjCfg.NOTIFICATION_SOUND.equals("true")) { notification.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); } } notificationManager.notify((int) (Math.random() * 1024 + 1), notification.build()); }
From source file:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java
private void notifyDebug() { final Resources res = getResources(); String contentTitle = "Debug Notification"; String contentText;//from ww w .j a v a2s. co m long currentTime = TimeUtils.getUTCTime(); long matchStart = TimeUtils.getUTCTime() + 60000; int minutesLeft = (int) (matchStart - currentTime + 59000) / 60000; if (minutesLeft < 2 && minutesLeft >= 0) { minutesLeft = 1; } if (minutesLeft < 0) { contentText = "debugNotification"; } else { contentText = "debugNotification"; } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this).setContentTitle(contentTitle) .setContentText(contentText).setColor(res.getColor(R.color.theme_primary)) .setTicker(contentTitle + " is about to start.") .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(NOTIFICATION_ARGB_COLOR, NOTIFICATION_LED_ON_MS, NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_notification).setPriority(Notification.PRIORITY_DEFAULT) .setAutoCancel(true); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notifBuilder.build()); }
From source file:rp.soi.dmsd.notextingwhilewalking.DetectedActivitiesIntentService.java
public void createNotification(boolean makeHeadsUpNotification) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_priority_high_black_24dp).setPriority(Notification.PRIORITY_DEFAULT) .setCategory(Notification.CATEGORY_MESSAGE).setContentTitle("No-Texting-While-Walking") .setContentText("It is hazardous to be texting while walking."); if (makeHeadsUpNotification) { Intent push = new Intent(getApplication(), MainActivity.class); push.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); //push.setClass(this, MainActivity.class); PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, push, PendingIntent.FLAG_CANCEL_CURRENT); notificationBuilder.setContentText("It is hazardous to be texting while walking.") .setFullScreenIntent(fullScreenPendingIntent, true); }//from w w w .ja va2s.co m Notification notification = notificationBuilder.build(); //---set the sound and lights--- notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_LIGHTS; //---gets an instance of the NotificationManager service--- NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); //---build the notification and issues it // with notification manager--- notificationManager.notify(WEARABLE_NOTIFICATION_ID, notification); }
From source file:org.android.gcm.client.GcmIntentService.java
private void sendNotification(String msg, String action) { NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = getPushactIntent(0); if (!action.isEmpty()) { intent.setAction(action);/*from w w w.java 2 s .c om*/ } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(getString(R.string.notification)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(1, mBuilder.build()); }
From source file:com.snappy.GCMIntentService.java
@SuppressWarnings("deprecation") public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras, String messageData) {//from w w w. ja v a 2s . c o m if (fromName != null) { final NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); 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), messageData, pendingIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_LIGHTS; String notificationId = Double.toString(Math.random()); notificationManager.notify(notificationId, 0, notification); } Log.i(LOG_TAG, message); Log.i(LOG_TAG, fromName); }