List of usage examples for android.media RingtoneManager getDefaultUri
public static Uri getDefaultUri(int type)
From source file:com.weddingsingers.wsapp.fcm.MyFirebaseMessagingService.java
private void sendNotification(ChatMessage m) { Intent intent = new Intent(this, SplashActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(SplashActivity.EXTRA_FRAGNAME, ChattingActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.manifest_ic_wedding_singers_512).setContentTitle("FCM Message") .setContentText(m.getSender().getName() + "? - " + m.getMessage()) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); /*Intent intent = new Intent(this, SplashActivity.class); intent.putExtra(ChattingActivity.EXTRA_USER, m.getSender()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.manifest_ic_wedding_singers_512) .setTicker("Chat Message")//from ww w. jav a2s . co m .setContentTitle(" ") .setContentText(m.getSender().getName() + "? - " + m.getMessage()) .setAutoCancel(true) .setDefaults(NotificationCompat.DEFAULT_ALL) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 *//* ID of notification *//*, notificationBuilder.build());*/ }
From source file:com.renjunzheng.vendingmachine.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from w w w.jav a2s. c o m */ private void sendNotification(String message) { Intent intent = new Intent(this, VMSelection.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.icon_w).setContentTitle("Ultimate Vending Machine").setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon)) .setColor(getColor(R.color.notification_color)); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:pt.up.mobile.syncadapter.SigarraSyncAdapter.java
private void syncNotifications(Account account, SyncResult syncResult) throws AuthenticationException, IOException { final User user = AccountUtils.getUser(getContext(), account.name); final String notificationReply = SifeupAPI.getReply(SifeupAPI.getNotificationsUrl(user.getUserCode()), account, getContext());//w w w. j a v a 2s. c o m final Gson gson = GsonUtils.getGson(); final Notification[] notifications = gson.fromJson(notificationReply, Notification[].class); if (notifications == null) { syncResult.stats.numParseExceptions++; LogUtils.trackException(getContext(), new RuntimeException(), notificationReply, true); return; } ArrayList<String> fetchedNotCodes = new ArrayList<String>(); ArrayList<ContentValues> bulkValues = new ArrayList<ContentValues>(); for (Notification not : notifications) { final ContentValues values = new ContentValues(); values.put(SigarraContract.Notifcations.CONTENT, gson.toJson(not)); fetchedNotCodes.add(not.getCode()); if (getContext().getContentResolver().update(SigarraContract.Notifcations.CONTENT_URI, values, SigarraContract.Notifcations.UPDATE_NOTIFICATION, SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, not.getCode())) == 0) { values.put(SigarraContract.Notifcations.CODE, account.name); values.put(SigarraContract.Notifcations.ID_NOTIFICATION, not.getCode()); values.put(SigarraContract.Notifcations.STATE, SigarraContract.Notifcations.NEW); values.put(SigarraContract.Notifcations.CODE, account.name); bulkValues.add(values); } } // inserting the values if (bulkValues.size() > 0) { getContext().getContentResolver().bulkInsert(SigarraContract.Notifcations.CONTENT_URI, bulkValues.toArray(new ContentValues[0])); // if the account being synced is the current active accout // display notification if (AccountUtils.getActiveUserName(getContext()).equals(account.name)) { final NotificationManager mNotificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(getContext()); notBuilder.setAutoCancel(true).setOnlyAlertOnce(true) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); if (bulkValues.size() == 1) { final Notification notification = gson.fromJson( bulkValues.get(0).getAsString(SigarraContract.Notifcations.CONTENT), Notification.class); Intent notifyIntent = new Intent(getContext(), NotificationsDescActivity.class) .putExtra(NotificationsDescFragment.NOTIFICATION, notification); // Creates the PendingIntent PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Sets the Activity to start in a new, empty task notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); notBuilder.setSmallIcon(R.drawable.icon).setTicker(notification.getMessage()) .setContentTitle(notification.getSubject()).setContentText(notification.getMessage()) .setContentIntent(notifyPendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(notification.getMessage()) .setBigContentTitle(notification.getSubject()) .setSummaryText(notification.getMessage())); mNotificationManager.notify(notification.getCode().hashCode(), notBuilder.build()); } else { final String notTitle = getContext().getString(R.string.new_notifications, bulkValues.size()); Intent notifyIntent = new Intent(getContext(), NotificationsActivity.class); // Sets the Activity to start in a new, empty task notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // Creates the PendingIntent PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // Sets a title for the Inbox style big view inboxStyle.setBigContentTitle(notTitle); // Moves events into the big view for (ContentValues value : bulkValues) { final Notification notification = gson.fromJson( value.getAsString(SigarraContract.Notifcations.CONTENT), Notification.class); inboxStyle.addLine(notification.getSubject()); } // Moves the big view style object into the notification // object. notBuilder.setStyle(inboxStyle); notBuilder.setSmallIcon(R.drawable.icon).setTicker(notTitle).setContentTitle(notTitle) .setContentText("").setContentIntent(notifyPendingIntent); mNotificationManager.notify(NotificationsFragment.class.getName().hashCode(), notBuilder.build()); } } } final Cursor syncState = getContext().getContentResolver().query(SigarraContract.LastSync.CONTENT_URI, SigarraContract.LastSync.COLUMNS, SigarraContract.LastSync.PROFILE, SigarraContract.LastSync.getLastSyncSelectionArgs(AccountUtils.getActiveUserName(getContext())), null); try { if (syncState.moveToFirst()) { if (syncState.getLong(syncState.getColumnIndex(SigarraContract.LastSync.NOTIFICATIONS)) == 0) { // Report that we have checked the notifications final ContentValues values = new ContentValues(); values.put(SigarraContract.LastSync.NOTIFICATIONS, System.currentTimeMillis()); getContext().getContentResolver().update(SigarraContract.LastSync.CONTENT_URI, values, SigarraContract.LastSync.PROFILE, SigarraContract.LastSync.getLastSyncSelectionArgs(account.name)); } } } finally { syncState.close(); } ArrayList<String> notToDelete = new ArrayList<String>(); final Cursor cursor = getContext().getContentResolver().query(SigarraContract.Notifcations.CONTENT_URI, new String[] { SigarraContract.Notifcations.ID_NOTIFICATION }, SigarraContract.Notifcations.PROFILE, SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name), null); try { if (cursor.moveToFirst()) { do { final String code = cursor.getString(0); if (!fetchedNotCodes.contains(code)) notToDelete.add(code); } while (cursor.moveToNext()); } else { // no notifications getContext().getContentResolver().notifyChange(SigarraContract.Notifcations.CONTENT_URI, null); } } finally { cursor.close(); } if (notToDelete.size() > 0) getContext().getContentResolver().delete(SigarraContract.Notifcations.CONTENT_URI, SigarraContract.Notifcations.getNotificationsDelete(notToDelete.toArray(new String[0])), SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, notToDelete.toArray(new String[0]))); syncResult.stats.numEntries += notifications.length; }
From source file:com.zaparound.MyFirebaseMessagingService.java
/** * Create and show a Inmylocation Notification. * * @param messageBody FCM message body received. *//*from w w w .ja v a 2 s. c o m*/ private void sendNotificationInmylocation(String messagetitle, String messageBody) { Intent intent = new Intent(this, LandingActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("CHATTAB_POSITION", 3); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); Notification notification = mBuilder.setSmallIcon(R.drawable.applogo).setTicker(messagetitle).setWhen(0) .setAutoCancel(true).setContentTitle(messagetitle) //.setNumber(++count) .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody)) //.setSubText("\n "+count+" new messages\n") .setContentIntent(pendingIntent) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.applogo)) .setContentText(messageBody).build(); NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification); }
From source file:com.sender.team.sender.gcm.MyGcmListenerService.java
private void sendNotification(String message) { Intent intent = new Intent(this, AcceptActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); 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).setTicker("SENDER").setContentTitle("SENDER") .setContentText("? ").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.gm.goldencity.util.Utils.java
/** * Play notification sound/*from w w w. j a v a 2 s .c o m*/ * * @param context Application context */ public static void playNotificationSound(Context context) { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, notification); r.play(); }
From source file:com.xorcode.andtweet.PreferencesActivity.java
protected void showRingtone(Object newValue) { String ringtone = (String) newValue; Uri uri;/*from w w w .j a v a2 s . com*/ Ringtone rt; if (ringtone == null) { uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } else if ("".equals(ringtone)) { mNotificationRingtone.setSummary(R.string.summary_preference_no_ringtone); } else { uri = Uri.parse(ringtone); rt = RingtoneManager.getRingtone(this, uri); mNotificationRingtone.setSummary(rt.getTitle(this)); } }
From source file:com.piggeh.palmettoscholars.services.MyFirebaseMessagingService.java
public void notifyUndefined(String title, String text) { Intent contentIntent = new Intent(this, MainActivity.class); //contentIntent.putExtra("navigation_page", MainActivity.PAGE_ANNOUNCEMENTS); contentIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, contentIntent, PendingIntent.FLAG_ONE_SHOT); Intent settingsIntent = new Intent(this, MainActivity.class); settingsIntent.putExtra("navigation_page", MainActivity.PAGE_SETTINGS); settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent settingsPendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, settingsIntent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle(); notifStyle.bigText(text);//from w w w . j ava 2s . co m notifStyle.setBigContentTitle(title); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon_nodpi).setContentTitle(title).setContentText(text) .setAutoCancel(true).setSound(defaultSoundUri) .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent) .setStyle(notifStyle); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Build the notification and issues it with notification manager. notificationManager.notify(NOTIFICATION_ID_UNDEFINED, notificationBuilder.build()); }
From source file:com.example.jendrik.moerder.FCM.MyFcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from www . ja va 2 s . co m */ private void sendNotification(String message) { //TODO wie baue ich die jeweilige Activity ein? //ist so schon richtig. Nur eben mit der richtigen Klasse. Anschlieend den Intent starten "startActivity(intent);" //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.sender.team.sender.gcm.MyGcmListenerService.java
private void sendRejectNotification() { Intent intent = new Intent(this, SplashActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(ACTION_REJECT, "reject"); 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).setTicker("SENDER").setContentTitle("SENDER") .setContentText("? ?").setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }