List of usage examples for android.media RingtoneManager getDefaultUri
public static Uri getDefaultUri(int type)
From source file:com.alobha.challenger.business.gmc.NotificationGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param challenge GCM challenge received. *//* ww w . j ava 2 s . c om*/ private void sendNotification(Challenge challenge) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("challenge_id", challenge.id); intent.setAction("ShowNotification"); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.inner_logo); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.inner_logo).setLargeIcon(largeIcon) .setContentTitle(getString(R.string.app_name)) .setContentText("You were challenged by " + challenge.owner.first_name).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.example.karan.bookdemo.chat.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from ww w .j av a2 s . c o m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, ChatList.class).putExtra("data", message).putExtra("sender", Sender); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, new Random().nextInt() /* 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("From:" + Sender).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(new Random().nextInt() /* ID of notification */, notificationBuilder.build()); }
From source file:com.neklo.demo.gcm.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.// ww w .j a v a 2 s . co m */ private void sendNotification(String title, 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(getApplication().getApplicationInfo().icon).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:br.com.alquest.alquestdemo.app.Services.GcmIntentService.java
private void sendNotification(String type, String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); String title = ""; Log.e(TAG, type);/*from w ww . jav a 2 s . c om*/ if (type.contains("message")) { title = getResources().getString(R.string.new_message); } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); long[] pattern = { 500, 500, 500, 500, 500, 500, 500, 500, 500 }; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setLights(0xFF0000FF, 100, 3000) .setVibrate(pattern).setSound(alarmSound).setSmallIcon(R.drawable.ic_launcher) .setContentTitle(title).setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.devbd.cttd.hello_ct.PushPkg.GcmBroadcastReceiver.java
private void sendNotification(Bundle bundle) { String msg = bundle.getString("price"); System.out.println(">>>>>>>>>>FFFF " + bundle.toString()); // String from_name=bundle.getString("From_Name"); // String type=bundle.getString("Type"); // String params=bundle.getString("Params"); // NotificationDetails nd=new NotificationDetails(); // nd.setBody(msg); // nd.setFrom_email(from_email); // nd.setFrom_name(from_name); // nd.setFrom_image(from_image); // /* ww w. j a v a 2s .co m*/ mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); // if (msg != null) { Noti.msg = msg; PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, new Intent(ctx, Noti.class), PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx).setSmallIcon(R.mipmap.icon) .setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), R.mipmap.icon)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentTitle(ctx.getResources().getString(R.string.app_name)).setAutoCancel(true) .setContentText(Html.fromHtml(msg)) .setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(msg))); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } }
From source file:com.wondereight.sensioair.gcm.SAGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*w w w. ja v a2 s .co m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, HomeActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(Constant.NOTI_MESSAGE, message); int requestCode = new Random().nextInt(); //System.currentTimeMillis() / 1000; PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode /* 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(getString(R.string.titleMessage)) //.setContentTitle("GCM Message") .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // int count = Integer.valueOf( sharedPreferences.getString(SAPreferences.COUNT_MESSAGES, "0") ); // sharedPreferences.edit().putString(SAPreferences.COUNT_MESSAGES, String.valueOf(count+1)).apply(); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); //notificationManager.notify(count /* ID of notification */, notificationBuilder.build()); }
From source file:com.appsaur.tarucassist.AlarmReceiver.java
@Override public void onReceive(Context context, Intent intent) { int mReceivedID = Integer.parseInt(intent.getStringExtra(BaseActivity.EXTRA_REMINDER_ID)); // Get notification title from Reminder Database ScheduleReminderDataSource scheduleReminderDataSource = new ScheduleReminderDataSource(context); StudentScheduleDataSource studentScheduleDataSource = new StudentScheduleDataSource(context); studentScheduleDataSource.open();/*from w ww.ja v a2 s .co m*/ ScheduleReminder scheduleReminder = scheduleReminderDataSource.getScheduleReminder(mReceivedID); String mTitle = scheduleReminder.getTitle(); int scheduleId = scheduleReminder.getScheduleId(); mCalendar = Calendar.getInstance(); String scheduleDate = studentScheduleDataSource.getCancelledScheduleById(scheduleId, BaseActivity.dateFormat.format(mCalendar.getTime())); if (!scheduleDate.equals("")) mTitle = mTitle + " - Cancelled"; // Create intent to open ReminderEditActivity on notification click Intent editIntent = new Intent(context, ViewScheduleActivity.class); editIntent.putExtra(BaseActivity.KEY_SCHEDULE_ID, Integer.toString(scheduleId)); 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_launcher)) .setSmallIcon(R.drawable.ic_timetable_white) .setContentTitle(context.getResources().getString(R.string.app_name)).setTicker(mTitle) .setContentText(mTitle).setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentIntent(mClick).setAutoCancel(true).setOnlyAlertOnce(true); NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nManager.notify(mReceivedID, mBuilder.build()); }
From source file:com.javathlon.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 a2 s . c o m*/ */ private void sendNotification(String title, String message, String type, String url) { Intent resultIntent = null; if (type.equals("podcast")) { resultIntent = new Intent(this, MainActivity.class); resultIntent.putExtra("needdownloaded", "y"); resultIntent.putExtra("rss", url); resultIntent.putExtra("action", "rsslist"); } else if (type.equals("web")) { resultIntent = new Intent(this, WebViewActivity.class); resultIntent.putExtra("url", url); } PendingIntent pendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, resultIntent, PendingIntent.FLAG_CANCEL_CURRENT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.controllers_play).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.eusecom.attendance.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *///from w ww . j a v a 2 s . 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.ic_stat_ic_notification).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.kectech.android.wyslink.service.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from w w w .j ava 2 s . com */ private void sendNotification(String message) { // Intent intent = new Intent(this, MainActivity.class); // intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); // http://stackoverflow.com/questions/5502427/resume-application-and-stack-from-notification // use the same intent filters as android uses when launches the app final Intent intent = new Intent(this, MainActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // http://stackoverflow.com/questions/25030710/gcm-push-notification-large-icon-size Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_notification_large); float multiplier = getImageFactor(getResources()); largeIcon = Bitmap.createScaledBitmap(largeIcon, (int) (largeIcon.getWidth() * multiplier), (int) (largeIcon.getHeight() * multiplier), false); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setLargeIcon(largeIcon).setSmallIcon(R.drawable.ic_stat_communication_message) .setContentTitle("wysLink Message").setContentText(message).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { // support from API 17 and above (Android 4.2) notificationBuilder.setSubText("click to open"); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Another issue i had in android lollipop is that the small icon was displayed next to the large icon. // http://stackoverflow.com/questions/16170648/android-notification-builder-show-a-notification-without-icon/33943309#33943309 Notification notification = notificationBuilder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { int smallIconViewId = this.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName()); if (smallIconViewId != 0) { if (notification.contentIntent != null) notification.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE); if (notification.headsUpContentView != null) notification.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE); if (notification.bigContentView != null) notification.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE); } } notificationManager.notify(0 /* ID of notification */, notification); }