List of usage examples for android.media RingtoneManager getDefaultUri
public static Uri getDefaultUri(int type)
From source file:com.silentcircle.contacts.detail.ContactLoaderFragment.java
private void doPickRingtone() { Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); // Allow user to pick 'Default' intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); // Show only ringtones intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE); // Don't show 'Silent' intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false); Uri ringtoneUri;//from w ww . j a v a 2s . com if (mCustomRingtone != null) { ringtoneUri = Uri.parse(mCustomRingtone); } else { // Otherwise pick default ringtone Uri so that something is selected. ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); } // Put checkmark next to the current ringtone for this contact intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneUri); // Launch! startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE); }
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);//from w w w.j a va 2s .c om player.prepare(); player.start(); } return player; }
From source file:edu.mit.viral.shen.DroidFish.java
/** * Plays device's default notification sound * *//*from w w w .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 . j av a2s.co 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); } }
From source file:com.coinblesk.client.KeyboardFragment.java
private void playNotificationSound() { try {//from w w w . ja v a2 s. c o m Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getActivity(), notification); r.play(); } catch (Exception e) { Log.e(TAG, "Error playing notification.", e); } }
From source file:com.PPRZonDroid.MainActivity.java
/** * Play warning sound if airspeed goes below the selected value * * @param context//from w w w . ja v a2 s . co m * @throws IllegalArgumentException * @throws SecurityException * @throws IllegalStateException * @throws IOException */ public void play_sound(Context context) throws IllegalArgumentException, SecurityException, IllegalStateException, IOException { Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); MediaPlayer mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(context, soundUri); final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); //Set volume max!!! audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, audioManager.getStreamMaxVolume(audioManager.STREAM_SYSTEM), 0); if (audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM) != 0) { mMediaPlayer.setAudioStreamType(AudioManager.STREAM_SYSTEM); mMediaPlayer.setLooping(true); mMediaPlayer.prepare(); mMediaPlayer.start(); } }
From source file:org.linphone.LinphoneService.java
private synchronized void startRinging() { try {// ww w .j a va 2 s .c o m if (mAudioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER) && mVibrator != null) { long[] patern = { 0, 1000, 1000 }; mVibrator.vibrate(patern, 1); } if (mRingerPlayer == null) { mRingerPlayer = new MediaPlayer(); mRingerPlayer.setAudioStreamType(AudioManager.STREAM_RING); mRingerPlayer.setDataSource(getApplicationContext(), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)); mRingerPlayer.prepare(); mRingerPlayer.setLooping(true); mRingerPlayer.start(); } else { Log.w(LinphoneService.TAG, "already ringing"); } } catch (Exception e) { Log.e(LinphoneService.TAG, "cannot handle incoming call", e); } }
From source file:com.sean.takeastand.alarmprocess.AlarmService.java
private void updateNotification() { /*if (!bRepeatingAlarmStepCheck) { mNotifTimePassed++;//from w w w . ja v a 2 s .c om } Log.i(TAG, "time since first notification: " + mNotifTimePassed + setMinutes(mNotifTimePassed));*/ 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]); rvRibbon.setTextViewText(R.id.notificationTimeStamp, notificationClockTime); /*rvRibbon.setTextViewText(R.id.stand_up_minutes, mNotifTimePassed + setMinutes(mNotifTimePassed)); rvRibbon.setTextViewText(R.id.topTextView, getString(R.string.stand_up_time_up));*/ NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this); alarmNotificationBuilder.setContent(rvRibbon); alarmNotificationBuilder.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\n" + mNotifTimePassed + setMinutes(mNotifTimePassed)) .extend(new NotificationCompat.WearableExtender().addAction( new NotificationCompat.Action.Builder(R.drawable.ic_action_done, "Stood", pendingIntents[1]) .build()) .setContentAction(0).setHintHideIcon(true) // .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.alarm_schedule_passed)) ); boolean[] alertType; if (mCurrentAlarmSchedule != null) { alertType = mCurrentAlarmSchedule.getAlertType(); } else { alertType = Utils.getDefaultAlertType(this); } if ((alertType[0])) { alarmNotificationBuilder.setLights(238154000, 1000, 4000); } if (Utils.getRepeatAlerts(this)) { if (alertType[1]) { boolean bUseLastStepCounters = false; if (!bRepeatingAlarmStepCheck) { bRepeatingAlarmStepCheck = true; bUseLastStepCounters = UseLastStepCounters(null); } if (!bUseLastStepCounters) { bRepeatingAlarmStepCheck = false; 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); }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void makeFavsNotification(ArrayList<String[]> tweets, Context context, boolean toDrawer) { String shortText;//from www . j ava 2 s .c o m String longText; String title; int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon; PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, null, 0); NotificationCompat.InboxStyle inbox = null; if (tweets.size() == 1) { title = tweets.get(0)[0]; shortText = tweets.get(0)[1]; longText = shortText; largeIcon = getImage(context, tweets.get(0)[2]); } else { inbox = new NotificationCompat.InboxStyle(); title = context.getResources().getString(R.string.favorite_users); shortText = tweets.size() + " " + context.getResources().getString(R.string.fav_user_tweets); longText = ""; try { inbox.setBigContentTitle(shortText); } catch (Exception e) { } if (tweets.size() <= 5) { for (String[] s : tweets) { inbox.addLine(Html.fromHtml("<b>" + s[0] + ":</b> " + s[1])); } } else { for (int i = 0; i < 5; i++) { inbox.addLine(Html.fromHtml("<b>" + tweets.get(i)[0] + ":</b> " + tweets.get(i)[1])); } inbox.setSummaryText("+" + (tweets.size() - 5) + " " + context.getString(R.string.tweets)); } largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } NotificationCompat.Builder mBuilder; AppSettings settings = AppSettings.getInstance(context); if (shortText.contains("@" + settings.myScreenName)) { // return because there is a mention notification for this already return; } Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } else { mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(2, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (context .getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, shortText); } // Light Flow notification sendToLightFlow(context, title, shortText); } }
From source file:com.nextgis.firereporter.GetFiresService.java
protected void onNotify(int nType, String sMsg) { String sFullMsg;//from ww w.j av a 2s .c om if (nType == 1) { //user nUserCount++; sFullMsg = getString(R.string.stUser) + sMsg; } else if (nType == 2) { //nasa nNasaCount++; sFullMsg = getString(R.string.stNasa) + sMsg; } else if (nType == 3) { //scanex nScanexCount++; sFullMsg = getString(R.string.stScanex) + sMsg; } else { return; } String sSumm = getString(R.string.stScanex) + nScanexCount + ", " + getString(R.string.stUser) + nUserCount + ", " + getString(R.string.stNasa) + nNasaCount; mBuilder.setContentText(sSumm); SharedPreferences prefs = getSharedPreferences(MainActivity.PREFERENCES, MODE_PRIVATE | MODE_MULTI_PROCESS); boolean bShowLed = prefs.getBoolean(SettingsActivity.KEY_PREF_NOTIFY_LED, true); boolean bSound = prefs.getBoolean(SettingsActivity.KEY_PREF_NOTIFY_SOUND, false); boolean bVibro = prefs.getBoolean(SettingsActivity.KEY_PREF_NOTIFY_VIBRO, false); if (bShowLed) mBuilder.setLights(Color.RED, 300, 4500); if (bSound) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(uri); } if (bVibro) { long[] vibraPattern = { 0, 500, 250, 500 }; mBuilder.setVibrate(vibraPattern); } mInboxStyle.setSummaryText(sSumm); mInboxStyle.addLine(sFullMsg); // Moves the big view style object into the notification object. mBuilder.setStyle(mInboxStyle); mNotificationManager.notify(STATE_NOTIFY_ID, mBuilder.build()); }