List of usage examples for android.media RingtoneManager getDefaultUri
public static Uri getDefaultUri(int type)
From source file:com.github.bettehem.androidtools.notification.CustomNotification.java
public static CustomNotification make(Context context, int iconId, String title, String message, Intent intent, boolean isPersistent, boolean dismissOnTap) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context); notificationBuilder.setSmallIcon(iconId); notificationBuilder.setContentTitle(title); notificationBuilder.setContentText(message); notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); notificationBuilder.build();//w w w . ja va2s. c om PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); notificationBuilder.setContentIntent(resultPendingIntent); notificationBuilder.setOngoing(isPersistent); notificationBuilder.setAutoCancel(dismissOnTap); return new CustomNotification(context, notificationBuilder); }
From source file:GCMService.java
private void sendNotification(String message) { Log.i("GCMService", "sendNotification()"); Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("GCM Message").setContentText(message) .setSound(notificationSoundUri).setLights(Color.BLUE, 500, 500); NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
From source file:MainActivity.java
public void clickLightsActionSound(View view) { NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("LightsActionSoundRedux") .setContentText("Lights, Action & Sound").setSound(notificationSoundUri) .setLights(Color.BLUE, 500, 500).setVibrate(new long[] { 250, 500, 250, 500, 250, 500 }); notificationManager.notify(0, notificationBuilder.build()); }
From source file:Main.java
/** * Get an alarm sound. Try for an alarm. If none set, try notification, otherwise, ringtone. * * @return Alarm media uri//from ww w .ja v a2s .com */ 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 w w. j a v a2 s. 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:GeofenceIntentService.java
private void sendNotification() { Log.i("GeofenceIntentService", "sendNotification()"); Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Geofence Alert") .setContentText("GEOFENCE_TRANSITION_DWELL").setSound(notificationSoundUri) .setLights(Color.BLUE, 500, 500); NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
From source file:com.achep.acdisplay.notifications.NotificationHelper.java
@NonNull public static Notification buildNotification(@NonNull Context context, final int id, @NonNull Object... objects) { final Resources res = context.getResources(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.stat_acdisplay).setColor(App.ACCENT_COLOR).setAutoCancel(true); PendingIntent pi = null;//from w ww . j a va 2 s . c om switch (id) { case App.ID_NOTIFY_TEST: { NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(res.getString(R.string.notification_test_message_large)); builder.setStyle(bts).setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.notification_test_message)) .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); break; } case App.ID_NOTIFY_BATH: { CharSequence contentText = (CharSequence) objects[0]; Intent contentIntent = (Intent) objects[1]; // Build notification pi = PendingIntent.getActivity(context, id, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentTitle(res.getString(R.string.service_bath)).setContentText(contentText) .setPriority(Notification.PRIORITY_MIN); break; } case App.ID_NOTIFY_INIT: { builder.setSmallIcon(R.drawable.stat_notify).setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.notification_init_text)) .setPriority(Notification.PRIORITY_MIN); break; } case App.ID_NOTIFY_APP_AUTO_DISABLED: { CharSequence summary = (CharSequence) objects[0]; NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(res.getString(R.string.permissions_auto_disabled)).setSummaryText(summary); builder.setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher)) .setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.permissions_auto_disabled)) .setPriority(Notification.PRIORITY_HIGH).setStyle(bts); break; } default: throw new IllegalArgumentException(); } if (pi == null) { pi = PendingIntent.getActivity(context, id, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); } return builder.setContentIntent(pi).build(); }
From source file:com.gaj2l.eventtus.services.notifications.NotificationService.java
private void sendNotification(String title, String messageBody) { Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.eventtus).setColor(getResources().getColor(R.color.colorPrimary, null)) .setContentTitle(title).setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
From source file:com.campusconnect.MyFirebaseMessagingService.java
@Override public void onCreate() { defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); inboxStyle = new NotificationCompat.InboxStyle(); super.onCreate(); notificationBuilder = new NotificationCompat.Builder(this); }
From source file:com.apptentive.android.example.push.MyGcmListenerService.java
@Override public void onMessageReceived(String from, Bundle data) { String title = data.getString("gcm.notification.title"); String body = data.getString("gcm.notification.body"); ApptentiveLog.e("From: " + from); ApptentiveLog.e("Title: " + title); ApptentiveLog.e("Body: " + body); Intent intent = new Intent(this, ExampleActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Apptentive.setPendingPushNotification(data); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification).setContentTitle(title).setContentText(body) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }