List of usage examples for android.media RingtoneManager getDefaultUri
public static Uri getDefaultUri(int type)
From source file:com.cfc.needblood.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w .j a va2s . c om*/ private static void generateNotification(Context context, String message) { long when = System.currentTimeMillis(); Intent notificationIntent = new Intent(context, MainActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); // Change the icons to conform Android's design guildeline builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.bd_icon)) .setTicker(message).setWhen(when).setAutoCancel(true) .setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.notification_message)); Notification notification = builder.build(); notificationManager.notify(0, notification); // Notification sound, comment out if do not need Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, ringtone); r.play(); }
From source file:com.lvbo.template.module.fcm.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./* w ww. j a v a 2 s .co m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); // intent.setData((Uri.parse("custom://"+ System.currentTimeMillis()))); // For multiple notification intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); int bgColor = getResources().getColor(R.color.colorPrimary); Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setLargeIcon(largeIcon) .setContentTitle(getString(R.string.app_name)).setContentText(message) // .setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent).setColor(bgColor) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId /* ID of notification */, notificationBuilder.build()); notificationId++; }
From source file:com.peppermint.peppermint.ui.AnswerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mGlowpad = (GlowPadWrapper) inflater.inflate(R.layout.answer_fragment, container, false); vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); myAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); Uri ring = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); r = RingtoneManager.getRingtone(getContext(), ring); r.play();//from w w w . jav a 2s .co m long[] pattern = { 100, 1000, 2000, 1000, 2000, 1000, 2000 }; vibrator.vibrate(pattern, 2); LOGD(TAG, " Creating view for answer fragment"); LOGD(TAG, "Created from activity" + getActivity()); mGlowpad.setAnswerListener(this); mGlowpad.startPing(); callActivity = (CallActivity) getContext(); return mGlowpad; }
From source file:be.ehb.fallwear.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from ww w. ja v a 2 s . co m*/ */ private void sendNotification(String message) { 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_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("GCM Message") .setContentText(message).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.rip.roomies.service.MessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param message FCM message body received. *///ww w .ja v a 2 s . c o m private void sendNotification(String title, String message) { Intent intent; if (MyApplication.isActivityVisible()) { switch (title) { case "Duty Completion": case "Duty Reminder": intent = new Intent(this, ListAllDuties.class); break; case "Shared Item Completion": case "Shared Item Reminder": intent = new Intent(this, ListAllGoods.class); break; case "Bill Reminder": intent = new Intent(this, Bills.class); break; default: intent = new Intent(this, Home.class); } } else { intent = new Intent(this, SplashScreen.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_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon((BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher))) .setContentTitle(title).setContentText(message).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.sendbird.android.CS185Project.fcm.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//* w w w.j ava2s .co m*/ 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_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.sendbird_ic_launcher).setContentTitle("SendBird") .setContentText(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.maxwen.wallpaper.firebase.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*ww w . j ava2 s. c o m*/ private void sendNotification(String messageBody) { Intent intent = new Intent(this, WallpaperBoardActivity.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_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_drawer_wallpapers).setContentTitle("FCM Message") .setContentText(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.kasoft.pushnot.GcmIntentService.java
private void sendNotification(String msg, String title, String form) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent appMainIntent = new Intent(getApplicationContext(), MainActivity.class); appMainIntent.putExtra("title", title); appMainIntent.putExtra("form", form); //appMainIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); appMainIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, appMainIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(form)).setContentText(form); mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:br.ufc.quixada.dsdm.myapplicationtestemulttabs.googleGCM.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.// w w w . ja v a 2 s .c om */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivityTabMensagens.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_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.mensageiro_icon).setContentTitle("MENSSAGEIRO").setContentText(message) .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.company.millenium.iwannask.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param data GCM message received./*from w ww .j ava2 s . c o m*/ */ private void sendNotification(Bundle data) { String question_body = data.getString("question_body"); String answer_body = data.getString("answer_body"); String question_id = data.getString("question_id"); //String answer_id = data.getString("answer_id"); String user_name = data.getString("user_name"); if (user_name != null && user_name.contains(" ")) { user_name = user_name.split(" ")[0]; } String type = data.getString("type"); Intent intent = new Intent(this, MainActivity.class); intent.putExtra("url", "/questions/" + question_id); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_CANCEL_CURRENT); String info = " answered:"; if (type != null && type.contentEquals("answer_feedback")) { String isLiked = data.getString("feedback_value"); info = " disliked your answer"; if (isLiked != null && isLiked.equals("true")) { info = " liked your answer"; } } else if (type != null && type.contentEquals("question_answer_op")) { info = " commented on"; } Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_comment_question_outline_grey600_36dp).setContentTitle(user_name + info) .setContentText(question_body) .setStyle(new NotificationCompat.BigTextStyle().bigText(question_body + "\n" + answer_body)) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(id, notificationBuilder.build()); id = id + 1; }