List of usage examples for android.media RingtoneManager TYPE_ALARM
int TYPE_ALARM
To view the source code for android.media RingtoneManager TYPE_ALARM.
Click Source Link
From source file:Main.java
public static Uri getAlarmRingtoneUri() { Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); if (alert == null) { // alert is null, using backup alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) { // I can't see this ever being null (as always // have a default notification) but just incase // alert backup is null, using 2nd backup alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); }/*from www . j av a2 s . co m*/ } return alert; }
From source file:Main.java
public static Uri getRandomRingtone(Context context) { Uri alert = null;/* w w w. jav a 2 s . c o m*/ RingtoneManager ringtoneManager = new RingtoneManager(context); ringtoneManager.setType(RingtoneManager.TYPE_ALARM); int count = ringtoneManager.getCursor().getCount(); int attempts = 0; do { int random = (int) Math.random() * (count + 1); alert = ringtoneManager.getRingtoneUri(random); } while (alert == null && ++attempts < 5); return alert; }
From source file:Main.java
/** * Gets a specific system string based on a ringtone type * @param type The ringtone type//from w ww. j a va2 s .c o m * @return A string representing the ringtone type */ private static String getStringByType(int type) { switch (type) { case RingtoneManager.TYPE_ALARM: return Settings.System.ALARM_ALERT; case RingtoneManager.TYPE_NOTIFICATION: return Settings.System.NOTIFICATION_SOUND; case RingtoneManager.TYPE_RINGTONE: return Settings.System.RINGTONE; default: return null; } }
From source file:Main.java
/** * Get an alarm sound. Try for an alarm. If none set, try notification, otherwise, ringtone. * * @return Alarm media uri/*w ww .ja v a2 s . co m*/ */ private static Uri getAlarmUri() { Uri alarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); if (alarm == null) { alarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alarm == null) { alarm = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); } } return alarm; }
From source file:com.contactmanager.home.assignmentreminder.AlarmReceiver.java
@Override public void onReceive(final Context context, Intent intent) { //this will update the UI with message TimeReminder inst = TimeReminder.instance(); inst.setAlarmText("Alarm!!! Assignment Start"); //this will sound the alarm tone //this will sound the alarm once, if you wish to //raise alarm in loop continuously then use MediaPlayer and setLooping(true) Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); if (alarmUri == null) { alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); }/*from w ww .j a v a 2s . c om*/ mRingtone = RingtoneManager.getRingtone(context, alarmUri); mRingtone.play(); //this will send a notification message ComponentName comp = new ComponentName(context.getPackageName(), AlarmService.class.getName()); startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); }
From source file:com.licenta.android.licenseapp.SchedulingService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent intentDismiss = new Intent(this, MainTabActivity.class); intentDismiss.putExtra(Constants.KEY_NOTIFICATION_ID, Constants.ALARM_ID); intentDismiss.putExtra(Constants.KEY_DISMISS_ALARM, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intentDismiss, PendingIntent.FLAG_UPDATE_CURRENT); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("HellO") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setCategory(Notification.CATEGORY_ALARM).setSound(alarmSound); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); mBuilder.setSound(Uri.parse(prefs.getString("alarm_ringtone", ""))); if (prefs.getBoolean("alarm_vibrate", false)) mBuilder.setVibrate(new long[] { 1000, 1000 }); mBuilder.addAction(0, getString(R.string.check_in), pendingIntent); mBuilder.addAction(R.drawable.ic_stat_action_alarm_off_notif, getString(R.string.dismiss_alarm), pendingIntent);// www. j a v a2 s. c o m //mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(Constants.ALARM_ID, mBuilder.build()); }
From source file:com.vncreatures.customItems.wakefulservice.AppService.java
private void updateNotification() { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); String userId = pref.getString(Common.USER_ID, null); HrmService service = new HrmService(); if (userId != null) { service.requestGetNotification(userId); service.setCallback(new ThreadTaskCallback() { @Override/*from w ww . j a v a 2 s . co m*/ public void onSuccess(ThreadModel threadModel) { int count = threadModel.countAllNotification(); if (count > 0) { Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alarmSound == null) { alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); if (alarmSound == null) { alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); } } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( getApplicationContext()).setSmallIcon(R.drawable.vnc_icon) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.notification_overall, count)) .setSound(alarmSound).setAutoCancel(true); // Creates an explicit intent for an Activity in your // app Intent resultIntent = new Intent(getApplicationContext(), LoginActivity.class); // The stack builder object will contain an artificial // back // stack for the // started Activity. // This ensures that navigating backward from the // Activity // leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext()); // Adds the back stack for the Intent (but not the // Intent // itself) stackBuilder.addParentStack(LoginActivity.class); // Adds the Intent that starts the Activity to the top // of // the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(Common.COMMON_ID, mBuilder.build()); } } @Override public void onError() { } }); } }
From source file:share.fair.miflas.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//* w w w . j a v a 2s .c om*/ private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("FCM Message") .setContentText("msg: " + messageBody).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.attiqrao.systemsltd.list_to_do.AlarmReceiver.java
@Override public void onReceive(Context context, Intent intent) { int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID)); // Get notification title from Reminder Database ReminderDatabase rb = new ReminderDatabase(context); Reminder reminder = rb.getReminder(mReceivedID); String mTitle = reminder.getTitle(); // Create intent to open ReminderEditActivity on notification click Intent editIntent = new Intent(context, ReminderEditActivity.class); editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID)); PendingIntent mClick = PendingIntent.getActivity(context, mReceivedID, editIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Create Notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_icon)) .setSmallIcon(R.mipmap.ic_icon).setContentTitle(context.getResources().getString(R.string.app_name)) .setTicker(mTitle).setContentText(mTitle) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)).setContentIntent(mClick) .setAutoCancel(true).setOnlyAlertOnce(true); NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nManager.notify(mReceivedID, mBuilder.build()); }
From source file:com.luan.thermospy.android.core.NotificationHandler.java
private NotificationCompat.Builder createBuilder(Context c, String temperature, boolean playSound) { String text = "Current temperature is " + temperature; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c) .setPriority(Notification.PRIORITY_HIGH).setAutoCancel(true).setContentTitle("Thermospy") .setContentText(text).setOnlyAlertOnce(false) .setSmallIcon(R.drawable.ic_stat_action_assignment_late); Uri alarmSound = null;/*from w w w.ja v a 2 s .c o m*/ if (playSound) { alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } mBuilder.setSound(alarmSound); Intent resultIntent = new Intent(c, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(c); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); return mBuilder; }