List of usage examples for android.media RingtoneManager TYPE_NOTIFICATION
int TYPE_NOTIFICATION
To view the source code for android.media RingtoneManager TYPE_NOTIFICATION.
Click Source Link
From source file:com.lambdasoup.quickfit.alarm.AlarmService.java
@WorkerThread private void refreshNotificationDisplay() { try (Cursor toNotify = getContentResolver().query(QuickFitContentProvider.getUriWorkoutsList(), new String[] { WorkoutEntry.SCHEDULE_ID, WorkoutEntry.WORKOUT_ID, WorkoutEntry.ACTIVITY_TYPE, WorkoutEntry.LABEL, WorkoutEntry.DURATION_MINUTES }, ScheduleEntry.TABLE_NAME + "." + ScheduleEntry.COL_SHOW_NOTIFICATION + "=?", new String[] { Integer.toString(ScheduleEntry.SHOW_NOTIFICATION_YES) }, null)) { int count = toNotify == null ? 0 : toNotify.getCount(); if (count == 0) { Timber.d("refreshNotificationDisplay: no events"); NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); notificationManager.cancel(Constants.NOTIFICATION_ALARM); return; }/*from ww w . j a v a 2 s . c om*/ long[] scheduleIds = new long[count]; int i = 0; toNotify.moveToPosition(-1); while (toNotify.moveToNext()) { scheduleIds[i] = toNotify.getLong(toNotify.getColumnIndex(WorkoutEntry.SCHEDULE_ID)); i++; } PendingIntent cancelIntent = PendingIntent.getService(getApplicationContext(), 0, getIntentOnNotificationsCanceled(this, scheduleIds), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notification; if (count == 1) { Timber.d("refreshNotificationDisplay: single event"); toNotify.moveToFirst(); notification = notifySingleEvent(toNotify, cancelIntent); } else { Timber.d("refreshNotificationDisplay: multiple events"); toNotify.moveToPosition(-1); notification = notifyMultipleEvents(toNotify, cancelIntent); } notification.setDeleteIntent(cancelIntent); notification.setAutoCancel(true); notification.setPriority(Notification.PRIORITY_HIGH); notification.setSmallIcon(R.drawable.ic_stat_quickfit_icon); notification.setColor(ContextCompat.getColor(this, R.color.colorPrimary)); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String ringtoneUriStr = preferences.getString(getString(R.string.pref_key_notification_ringtone), null); if (ringtoneUriStr == null) { notification.setSound( RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION)); } else if (!ringtoneUriStr.isEmpty()) { notification.setSound(Uri.parse(ringtoneUriStr)); } boolean ledOn = preferences.getBoolean(getString(R.string.pref_key_notification_led), true); boolean vibrationOn = preferences.getBoolean(getString(R.string.pref_key_notification_vibrate), true); notification.setDefaults( (ledOn ? Notification.DEFAULT_LIGHTS : 0) | (vibrationOn ? Notification.DEFAULT_VIBRATE : 0)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notification.setCategory(Notification.CATEGORY_ALARM); } NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(Constants.NOTIFICATION_ALARM, notification.build()); } }
From source file:com.nbplus.vbroadlauncher.BroadcastPushReceiver.java
private void playNotificationAlarm(Context context, int textResId) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSound(soundUri);/*from w w w . j ava 2 s. c om*/ notificationManager.notify(Constants.PUSH_NOTIFICATION_ALARM_ID, builder.build()); Toast.makeText(context, textResId, Toast.LENGTH_SHORT).show(); }
From source file:com.nbplus.vbroadlauncher.BroadcastPushReceiver.java
private void showNotification(Context context, int notificationId, String title, String contentText, String bigTitle, String bigContentText, String summaryText, String ticker, Intent intent) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSound(soundUri);//from w ww . j a va 2 s . com builder.setSmallIcon(R.drawable.ic_notification_noti); builder.setWhen(System.currentTimeMillis()); //builder.setNumber(10); if (!StringUtils.isEmptyString(ticker)) { builder.setTicker(ticker); } if (StringUtils.isEmptyString(title)) { builder.setContentTitle(PackageUtils.getApplicationName(context)); } else { builder.setContentTitle(title); } builder.setContentText(contentText); builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); builder.setAutoCancel(true); // big title and text if (!StringUtils.isEmptyString(bigTitle) && !StringUtils.isEmptyString(bigContentText)) { NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder); if (!StringUtils.isEmptyString(summaryText)) { style.setSummaryText(summaryText); } style.setBigContentTitle(bigTitle); style.bigText(bigContentText); builder.setStyle(style); } if (intent != null) { PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); } notificationManager.notify(notificationId, builder.build()); }
From source file:com.visva.voicerecorder.utils.Utils.java
public static void showNotificationAfterCalling(Context context, String phoneName, String phoneNo, String createdDate) {/* w w w.jav a 2 s .c o m*/ Resources res = context.getResources(); String newRecord = res.getString(R.string.you_have_new_record); String favorite = res.getString(R.string.favourite); String addNote = res.getString(R.string.add_note); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setContentTitle(phoneName) .setContentText(newRecord); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); builder.setSound(alarmSound); int isFavourite = Utils.isCheckFavouriteContactByPhoneNo(context, phoneNo); Bundle bundle = new Bundle(); bundle.putString(MyCallRecorderConstant.EXTRA_PHONE_NAME, phoneName); bundle.putString(MyCallRecorderConstant.EXTRA_PHONE_NO, phoneNo); bundle.putString(MyCallRecorderConstant.EXTRA_CREATED_DATE, createdDate); if (isFavourite == 0) { //favorite intent Intent favoriteIntent = new Intent(); favoriteIntent.setAction(MyCallRecorderConstant.FAVORITE_INTENT); favoriteIntent.putExtras(bundle); PendingIntent pendingFavoriteIntent = PendingIntent.getBroadcast(context, MyCallRecorderConstant.NOTIFICATION_ID, favoriteIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(R.drawable.ic_star_outline_white_36dp, favorite, pendingFavoriteIntent); } //Make a note intent Intent makeNoteIntent = new Intent(); makeNoteIntent.setAction(MyCallRecorderConstant.MAKE_NOTE_INTENT); makeNoteIntent.putExtras(bundle); PendingIntent pendingMakeNoteIntent = PendingIntent.getBroadcast(context, MyCallRecorderConstant.NOTIFICATION_ID, makeNoteIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(R.drawable.ic_customer_create, addNote, pendingMakeNoteIntent); Intent resultIntent = new Intent(context, ActivityHome.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(ActivityHome.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(resultPendingIntent); builder.setPriority(NotificationCompat.PRIORITY_MAX); builder.setWhen(0); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(MyCallRecorderConstant.NOTIFICATION_ID, builder.build()); }
From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java
private Uri getNotificationSoundUri(Context context, String sound) { Uri uri = null;// w ww. j a v a 2s .com if (sound == null) { uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } else if (!(sound.trim().isEmpty())) { String soundResourceString = sound; try { if (soundResourceString.contains(".")) { soundResourceString = soundResourceString.substring(0, soundResourceString.indexOf(".")); } int resourceId = getResourceId(context, RAW, soundResourceString); if (resourceId == -1) { logger.error( "MFPPushIntentService:getNotificationSoundUri() - Specified sound file is not found in res/raw"); } uri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resourceId); } catch (Exception e) { logger.error("MFPPushIntentService:getNotificationSoundUri() - Exception while parsing sound file"); } } return uri; }
From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java
private Notification createNotification(final int iconResId, final String title, final String contentText, final String imageUrl, final String imageIconUrl, final String imageSmallIconUrl, final PendingIntent contentIntent) { log.info("Create Notification:" + title + ", Content:" + contentText); if (android.os.Build.VERSION.SDK_INT < ANDROID_JELLYBEAN) { return createLegacyNotification(iconResId, title, contentText, contentIntent); }//from w w w .j av a 2 s.c om if (!initClassesAndMethodsByReflection()) { // fall back to creating the legacy notification. return createLegacyNotification(iconResId, title, contentText, contentIntent); } final Object notificationBuilder; final Object bigTextStyle; final Object bigPictureStyle; try { notificationBuilder = notificationBuilderConstructor .newInstance(pinpointContext.getApplicationContext()); bigTextStyle = notificationBigTextStyleClass.newInstance(); bigPictureStyle = notificationBigPictureStyleClass.newInstance(); } catch (final InvocationTargetException ex) { log.debug("Can't invoke notification builder constructor. : " + ex.getMessage(), ex); return createLegacyNotification(iconResId, title, contentText, contentIntent); } catch (final IllegalAccessException ex) { log.debug("Can't access notification builder or bigTextStyle or bigPictureStyle classes. : " + ex.getMessage(), ex); return createLegacyNotification(iconResId, title, contentText, contentIntent); } catch (final InstantiationException ex) { log.debug( "Exception while instantiating notification builder or bigTextStyle or bigPictureStyle classes. : " + ex.getMessage(), ex); return createLegacyNotification(iconResId, title, contentText, contentIntent); } try { setContentTitleMethod.invoke(notificationBuilder, title); setContentTextMethod.invoke(notificationBuilder, contentText); setContentIntent.invoke(notificationBuilder, contentIntent); setPriorityMethod.invoke(notificationBuilder, 1); final Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); setSoundMethod.invoke(notificationBuilder, defaultSoundUri); if (!buildNotificationIcons(iconResId, imageIconUrl, imageSmallIconUrl, notificationBuilder)) { return createLegacyNotification(iconResId, title, contentText, contentIntent); } if (imageUrl != null) { try { notificationImage = new DownloadImageTask().execute(imageUrl).get(); if (notificationImage != null) { bigPictureMethod.invoke(bigPictureStyle, notificationImage); setSummaryMethod.invoke(bigPictureStyle, contentText); setStyleMethod.invoke(notificationBuilder, bigPictureStyle); } else { bigTextMethod.invoke(bigTextStyle, contentText); setStyleMethod.invoke(notificationBuilder, bigTextStyle); } } catch (final InterruptedException e) { log.error("Interrupted when downloading image : " + e.getMessage(), e); } catch (final ExecutionException e) { log.error("Failed execute download image thread : " + e.getMessage(), e); } } return (Notification) buildMethod.invoke(notificationBuilder); } catch (final InvocationTargetException ex) { log.debug("Can't invoke notification builder methods. : " + ex.getMessage(), ex); return createLegacyNotification(iconResId, title, contentText, contentIntent); } catch (final IllegalAccessException ex) { log.debug("Can't access notification builder methods. : " + ex.getMessage(), ex); return createLegacyNotification(iconResId, title, contentText, contentIntent); } }
From source file:com.visva.voicerecorder.utils.Utils.java
public static void showNotificationAtReminderTime(Context context, String title, String note) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setContentTitle(title) .setContentText(note);/* ww w .j av a 2s . c o m*/ Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); builder.setSound(alarmSound); Intent resultIntent = new Intent(context, ActivityHome.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(ActivityHome.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, builder.build()); }
From source file:com.hhunj.hhudata.ForegroundService.java
private MediaPlayer ring() throws Exception, IOException { Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); MediaPlayer player = new MediaPlayer(); player.setDataSource(this, alert); final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION) != 0) { player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); player.setLooping(true);/* ww w .j a v a2 s.c o m*/ player.prepare(); player.start(); } return player; }
From source file:edu.mit.viral.shen.DroidFish.java
/** * Plays device's default notification sound * *//*www . j a v a2 s. co m*/ public void playBeep() { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.sean.takeastand.alarmprocess.AlarmService.java
private void sendNotification() { NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent[] pendingIntents = makeNotificationIntents(); RemoteViews rvRibbon = new RemoteViews(getPackageName(), R.layout.stand_notification); rvRibbon.setOnClickPendingIntent(R.id.btnStood, pendingIntents[1]); notificationClockTime = Utils.getFormattedCalendarTime(Calendar.getInstance(), this); rvRibbon.setTextViewText(R.id.notificationTimeStamp, notificationClockTime); NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this); alarmNotificationBuilder.setContent(rvRibbon).setContentIntent(pendingIntents[0]).setAutoCancel(false) .setTicker(getString(R.string.stand_up_time_low)).setSmallIcon(R.drawable.ic_notification_small) .setContentTitle("Take A Stand ").setContentText( "Mark Stood") .extend(new NotificationCompat.WearableExtender().addAction( new NotificationCompat.Action.Builder(R.drawable.ic_action_done, "Stood", pendingIntents[2]) .build())//from w ww . ja v a2 s.c o m .setContentAction(0).setHintHideIcon(true) // .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.alarm_schedule_passed)) ); //Purpose of below is to figure out what type of user alert to give with the notification //If scheduled, check settings for that schedule //If unscheduled, check user defaults if (mCurrentAlarmSchedule != null) { boolean[] alertType = mCurrentAlarmSchedule.getAlertType(); if ((alertType[0])) { alarmNotificationBuilder.setLights(238154000, 1000, 4000); } if (alertType[1]) { alarmNotificationBuilder.setVibrate(mVibrationPattern); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT && Utils.getVibrateOverride(this)) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(mVibrationPattern, -1); } } if (alertType[2]) { Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); alarmNotificationBuilder.setSound(soundUri); } } else { boolean[] alertType = Utils.getDefaultAlertType(this); if ((alertType[0])) { alarmNotificationBuilder.setLights(238154000, 1000, 4000); } if (alertType[1]) { alarmNotificationBuilder.setVibrate(mVibrationPattern); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT && Utils.getVibrateOverride(this)) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(mVibrationPattern, -1); } } if (alertType[2]) { Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); alarmNotificationBuilder.setSound(soundUri); } } Notification alarmNotification = alarmNotificationBuilder.build(); notificationManager.notify(R.integer.AlarmNotificationID, alarmNotification); if (getSharedPreferences(Constants.USER_SHARED_PREFERENCES, 0).getBoolean(Constants.STANDDTECTORTM_ENABLED, false)) { Intent standSensorIntent = new Intent(this, StandDtectorTM.class); standSensorIntent.setAction(com.heckbot.standdtector.Constants.STANDDTECTOR_START); standSensorIntent.putExtra("MILLISECONDS", (long) 60000); standSensorIntent.putExtra("pendingIntent", pendingIntents[1]); startService(standSensorIntent); } }