List of usage examples for android.media RingtoneManager getDefaultUri
public static Uri getDefaultUri(int type)
From source file:com.carpool.dj.carpool.model.GcmIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//* w w w .j a v a 2 s .co m*/ @SuppressWarnings("deprecation") private static void generateNotification(Context context, String message, Bundle data, String type) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Notification notification = new Notification(icon, message, when); Notification notification = new Notification.Builder(context) .setContentTitle(Utils.nowActivity.getString(R.string.app_name)).setContentText(message) .setSmallIcon(icon).setWhen(when).setSound(alarmSound).build(); // String title = context.getString(R.string.app_name); Intent notificationIntent = null; if ("CarEvent".equals(type)) { notificationIntent = new Intent(context, ContentActivity.class); } else { return; } notificationIntent.putExtras(data); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, Utils.nowActivity.getString(R.string.app_name), message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.mobilewrapper.base.gcm.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.// w w w . j a v a 2s. co m */ private void sendNotification(PushMessage message) { Intent intent = new Intent(this, SplashActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra(WrapperApplication.EXTRA_SERIAL_PUSHMSG, message); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Style style = null; if (message.getThumb() == null || message.getThumb().equals("")) { style = new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(message.getDescription())); } else { Bitmap remote_picture = null; try { remote_picture = BitmapFactory.decodeStream((InputStream) new URL(message.getThumb()).getContent()); } catch (IOException e) { } style = new NotificationCompat.BigPictureStyle().bigPicture(remote_picture) .setSummaryText(Html.fromHtml(message.getDescription())); } Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setTicker(message.getTitle()).setContentTitle(message.getTitle()) .setContentText(message.getDescription()).setAutoCancel(true).setSound(defaultSoundUri) .setStyle(style).setContentIntent(pendingIntent); if (style instanceof NotificationCompat.BigPictureStyle) { notificationBuilder.setContentText(getString(R.string.notification_bigPictureContentText)); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.karbide.bluoh.notification.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *///from www . ja v a 2 s . com private void sendNotification(String title, String messageBody, String TrueOrFalse) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("AnotherActivity", TrueOrFalse); 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).setContentTitle(title).setContentText(messageBody) .setStyle(new NotificationCompat.BigTextStyle().bigText(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.godowondev.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from w ww. j av a 2s .com */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (message.startsWith("[ADDITIONAL_MAIL_RING")) { intent.putExtra("navi_type", "additional_mail"); //defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); defaultSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.wakeup); //sendSMS("01099989584", message); } else { intent.putExtra("navi_type", "reservation_error"); } PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.logo).setContentTitle("?? PUSH ").setContentText(message) .setAutoCancel(true).setContentIntent(pendingIntent); if (message.startsWith("[ADDITIONAL_MAIL_SMS")) { //notificationBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }); notificationBuilder.setSound(defaultSoundUri); } else if (message.startsWith("[ADDITIONAL_MAIL_RING")) { AudioManager audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audiomanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); notificationBuilder.setSound(defaultSoundUri); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Notification note = notificationBuilder.build(); if ((message.startsWith("[ADDITIONAL_MAIL_SMS_KYS]") || message.startsWith("[ADDITIONAL_MAIL_SMS_ALL]") || message.startsWith("[ADDITIONAL_MAIL_RING_KYS]") || message.startsWith("[ADDITIONAL_MAIL_RING_ALL]")) && getResources().getString(R.string.member_name).equals("?")) { notificationManager.notify(0 /* ID of notification */, note); } if ((message.startsWith("[ADDITIONAL_MAIL_SMS_KDW]") || message.startsWith("[ADDITIONAL_MAIL_SMS_ALL]") || message.startsWith("[ADDITIONAL_MAIL_RING_KDW]") || message.startsWith("[ADDITIONAL_MAIL_RING_ALL]")) && getResources().getString(R.string.member_name).equals("")) { notificationManager.notify(0 /* ID of notification */, note); } //note.flags = Notification.FLAG_INSISTENT; // ? ? //notificationManager.notify(0 /* ID of notification */, note); }
From source file:com.jameswolfeoliver.pigeon.Managers.NotificationsManager.java
private static NotificationCompat.Builder getNotificationBuilder(Context context, String title, String summary, String body) {/* ww w . jav a 2s. c om*/ Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.app_icon).setContentTitle(title).setContentText(summary) .setStyle(new NotificationCompat.BigTextStyle().bigText(body)).setAutoCancel(true) .setSound(defaultSoundUri); return builder; }
From source file:com.konsula.app.gcm.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*w ww . j a va 2s . co m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(MainActivity.togo, togo); intent.putExtra(MainActivity.bundle, bundle); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_UPDATE_CURRENT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Konsula").setContentText(message) .setAutoCancel(true).setPriority(Notification.PRIORITY_MAX).setSound(defaultSoundUri) .setLights(0xff00ff00, 300, 100).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setVibrate(new long[] { 1000, 1000 }).setTicker("New messages from Konsula!") .setContentIntent(pendingIntent); //notificationBuilder.setOngoing(true); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:andre.com.datapushandroid.services.FCMService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *///w w w .ja va 2 s. com 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.mipmap.ic_launcher).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.thyn.broadcast.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from w w w . j a v a 2 s .c om */ private void sendNotification(String sender, String profileID, String message, String taskID) { //Intent intent = new Intent(this, MainActivity.class); //Intent intent = new Intent(this, TaskIWillHelpPagerViewOnlyActivity.class); /* 11/02 Don't use MainActivity.class or TaskIWillHelpPagerViewOnlyActivity.class. It will crash with this exception java.lang.IllegalArgumentException: No view found for id 0x1020002 (android:id/content). This is because in TaskListFragment, there is this code -> DashboardFragment dashboardFragment = new DashboardFragment(); FragmentManager manager = getActivity().getSupportFragmentManager(); manager.beginTransaction().replace(R.id.navigation_fragment_container, dashboardFragment, dashboardFragment.getTag()).addToBackStack(null).commit(); This code requires that fragment that needs to be replaced is R.id.navigation_fragment_container. This code got fixed when I added the line "Intent intent = new Intent(this, NavigationActivity.class) */ Intent intent = new Intent(this, NavigationActivity.class); //intent.putExtra("broadcast","comingFromBroadcast"); //intent.putExtra("message", message); //intent.putExtra("sender", sender); //intent.putExtra("profileID", profileID); //intent.putExtra("taskID", taskID); //intent.putExtra(com.thyn.task.view.iwillhelp.TaskIWillHelpPagerViewOnlyFragment.EXTRA_TASK_ID, taskID); // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */ , intent, PendingIntent.FLAG_UPDATE_CURRENT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("thyNeighbr") .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); notificationBuilder.setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); //updateChatRoomFragment(sender, profileID, message); }
From source file:com.android.talkbacktests.testsession.NotificationTest.java
private void showCustomNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext()).setAutoCancel(true) .setSmallIcon(android.R.drawable.ic_notification_overlay) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); RemoteViews contentView = new RemoteViews(getContext().getPackageName(), R.layout.custom_notification); contentView.setImageViewResource(R.id.notification_image, android.R.drawable.ic_dialog_email); contentView.setTextViewText(R.id.notification_title, getString(R.string.custom_notification_title)); contentView.setTextViewText(R.id.notification_text, getString(R.string.custom_notification_text)); builder.setContent(contentView);/*from ww w .j av a2 s. c o m*/ Intent resultIntent = new Intent(getContext(), MainActivity.class); resultIntent.setAction(Intent.ACTION_MAIN); resultIntent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, resultIntent, 0); builder.setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID_LAST_VIEW, builder.build()); }
From source file:com.live.tj98.chatsnap.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *///from ww w . ja va 2 s .c o m protected void sendNotification(String sender, String messageBody) { Intent intent = new Intent(MyFirebaseMessagingService.this, ChatsActivity.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.background_splash).setContentTitle(sender).setContentText(messageBody) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }