private void setPowerNotificationRingtone(Intent intent) { final Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); final String toneName; final String toneUriPath; if ( uri != null ) { final Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), uri); toneName = ringtone.getTitle(getActivity()); toneUriPath = uri.toString(); } else { // silent toneName = getString(R.string.power_notifications_ringtone_silent); toneUriPath = POWER_NOTIFICATIONS_SILENT_URI; } mPowerSoundsRingtone.setSummary(toneName); CMSettings.Global.putString(getContentResolver(), CMSettings.Global.POWER_NOTIFICATIONS_RINGTONE, toneUriPath); }
public NotificationCompat.Builder showNotification() { Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); notificationId = (int) new Date().getTime(); mNotifyManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(getActivity()); mBuilder.setContentTitle("Sending mail to " + this.company.getCompanyName()) .setContentText("Sending...") .setSound(defaultSoundUri) .setSmallIcon(R.drawable.ic_stat_name); mBuilder.setProgress(100, 100, true); // Displays the progress bar for the first time. mNotifyManager.notify(notificationId, mBuilder.build()); return mBuilder; }
/** * Beep plays the default notification ringtone. * * @param count Number of times to play notification */ public void beep(final long count) { cordova.getThreadPool().execute(new Runnable() { public void run() { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(cordova.getActivity().getBaseContext(), ringtone); // If phone is not set to silent mode if (notification != null) { for (long i = 0; i < count; ++i) { notification.play(); long timeout = 5000; while (notification.isPlaying() && (timeout > 0)) { timeout = timeout - 100; try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } } } }); }
static void showUpdateAvailableNotification(Context context, String title, String content, UpdateFrom updateFrom, URL apk, int smallIconResourceId) { PendingIntent contentIntent = PendingIntent.getActivity(context, 0, context.getPackageManager().getLaunchIntentForPackage(UtilsLibrary.getAppPackageName(context)), PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent pendingIntentUpdate = PendingIntent.getActivity(context, 0, UtilsLibrary.intentToUpdate(context, updateFrom, apk), PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentIntent(contentIntent) .setContentTitle(title) .setContentText(content) .setStyle(new NotificationCompat.BigTextStyle().bigText(content)) .setSmallIcon(smallIconResourceId) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setOnlyAlertOnce(true) .setAutoCancel(true) .addAction(R.drawable.ic_system_update_white_24dp, context.getResources().getString(R.string.appupdater_btn_update), pendingIntentUpdate); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, builder.build()); }
static void showUpdateNotAvailableNotification(Context context, String title, String content, int smallIconResourceId) { PendingIntent contentIntent = PendingIntent.getActivity(context, 0, context.getPackageManager().getLaunchIntentForPackage(UtilsLibrary.getAppPackageName(context)), PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentIntent(contentIntent) .setContentTitle(title) .setContentText(content) .setStyle(new NotificationCompat.BigTextStyle().bigText(content)) .setSmallIcon(smallIconResourceId) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setOnlyAlertOnce(true) .setAutoCancel(true); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, builder.build()); }
@NonNull public static String getRingtoneName(@NonNull Context context, @Nullable Uri uri) { String title = context.getString(R.string.sound_chooser_summary); if (uri != null) { Ringtone ringtone = RingtoneManager.getRingtone(context, uri); if (ringtone != null) { return ringtone.getTitle(context); } else { try (Cursor cur = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.Media.TITLE}, MediaStore.Audio.Media._ID + " =?", new String[]{uri.getLastPathSegment()}, null)) { if (cur != null) { title = cur.getString(1); if (InputHelper.isEmpty(title)) { title = cur.getString(cur.getColumnIndex(MediaStore.Audio.Media.TITLE)); } } } catch (Exception ignored) {} } } return title; }
/** * Muestra que ha habido una nueva notificación * @param notification * @param data */ private void displayNotification(RemoteMessage.Notification notification, Map<String, String> data) { Intent intent = new Intent(this, MainActivity.class); intent.putExtra("notificacion","notificacion"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(notification.getTitle()) .setContentText(notification.getBody()) .setAutoCancel(true) .setSound(defaultSoundUri) .setSmallIcon(R.mipmap.ic_launch) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
@Override public void onReceive(Context context, Intent intent) { Intent intent2 = new Intent(context, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context) .setAutoCancel(true) //Automatically delete the notification .setSmallIcon(R.drawable.water_bottle_flat) //Notification icon .setContentIntent(pendingIntent) .setContentTitle("Time to hydrate") .setContentText("Drink a glass of water now") .setCategory(Notification.CATEGORY_REMINDER) .setPriority(Notification.PRIORITY_HIGH) .setSound(defaultSoundUri); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(0, notificationBuilder.build()); Toast.makeText(context, "Repeating Alarm Received", Toast.LENGTH_SHORT).show(); }
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. */ private void sendNotification(String messageBody) { Intent intent = new Intent(this, QuakeActivity.class);//**The activity that you want to open when the notification is clicked 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_error_outline_white_24dp) .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()); }
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) { if (resultCode == Activity.RESULT_OK && requestCode == 5) { Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); SharedPreferences myPrefs = this.getSharedPreferences(SettingConstants.PREFERENCES, MODE_PRIVATE); SharedPreferences.Editor prefsEditor = myPrefs.edit(); if (uri != null) { prefsEditor.putString(SettingConstants.SOUNDFILE, uri.toString()); prefsEditor.apply(); Log.d(TAG, "Chosen sound: " + uri.toString()); Answers.getInstance().logCustom(new CustomEvent("Sound") .putCustomAttribute("uri", uri.toString())); } else { prefsEditor.putString(SettingConstants.SOUNDFILE, ""); prefsEditor.apply(); } TextView soundTV = (TextView) findViewById(R.id.textViewCurrentSound); soundTV.setText(myPrefs.getString(SettingConstants.SOUNDFILE, SettingConstants.SOUNDFILE_DEFAULT)); } }
/** * Handles incoming data events from the mesh - toasts the contents of the data. * * @param e event object from mesh */ private void handleDataReceived(MeshManager.RightMeshEvent e) { final MeshManager.DataReceivedEvent event = (MeshManager.DataReceivedEvent) e; runOnUiThread(new Runnable() { @Override public void run() { // Toast data contents. String message = new String(event.data); Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show(); // Play a notification. Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(MainActivity.this, notification); r.play(); } }); }
public Map<String, String> getNotifications() { RingtoneManager manager = new RingtoneManager(getActivity()); manager.setType(RingtoneManager.TYPE_NOTIFICATION); Cursor cursor = manager.getCursor(); Map<String, String> list = new HashMap<>(); while (cursor.moveToNext()) { String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX); Uri notificationUri = manager.getRingtoneUri(cursor.getPosition()); list.put(notificationTitle, notificationUri.toString()); } list.put(getString(R.string.ringtone_vk), Settings.get() .notifications() .getDefNotificationRingtone()); return list; }
/** * Get the tone from {@link RingtoneManager} for any given type. It will add title as the key and * uri of the sound as value in given hashmap. * * @param context instance of the caller * @param type type of the ringtone from {@link RingtonePickerDialog.Builder#TYPE_NOTIFICATION}, * {@link RingtonePickerDialog.Builder#TYPE_RINGTONE} or {@link RingtonePickerDialog.Builder#TYPE_ALARM} * @param ringTonesList Hash map in which alarm tone will be added. */ private static void getTone(Context context, int type, @NonNull HashMap<String, Uri> ringTonesList) { RingtoneManager mRingtoneMgr = new RingtoneManager(context); mRingtoneMgr.setType(type); Cursor ringsCursor = mRingtoneMgr.getCursor(); while (ringsCursor.moveToNext()) { ringTonesList.put(ringsCursor.getString(RingtoneManager.TITLE_COLUMN_INDEX), Uri.parse(ringsCursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/" + ringsCursor.getString(RingtoneManager.ID_COLUMN_INDEX))); } ringsCursor.close(); }
/** * Method send notification * * @param message message object */ private void sendNotification(Message message) { Intent intent = new Intent(this, ChatActivity.class); intent.putExtra("message", message); intent.putExtra("id", message.getSender()); intent.putExtra("name", name); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, 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("Chat cDa") .setContentText(message.getMessage()) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); int requestCode = 0; PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_action_name) .setContentTitle("FCM Message") .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int notificationId = 0; notificationManager.notify(notificationId, notificationBuilder.build()); }
private void startPlayingRing() { RingtoneManager ringtoneManager = new RingtoneManager(this); ringtoneManager.setType(RingtoneManager.TYPE_ALARM); ringtoneManager.getCursor(); Uri ringtoneUri = ringtoneManager.getRingtoneUri(alarm.ringPosition); AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 7, AudioManager.ADJUST_SAME); mediaPlayer = new MediaPlayer(); try { mediaPlayer.setDataSource(this, ringtoneUri); mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.prepare(); mediaPlayer.start(); mediaPlayer.setLooping(true); } catch (IOException e) { e.printStackTrace(); } }
private void handleMessage(RemoteMessage remoteMessage) { Intent intent = new Intent(this, FirebaseAuth.getInstance().getCurrentUser() == null ? LoginActivity.class:MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent intent1 = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT); Uri defaultURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder builder = new NotificationCompat.Builder(this,NotificationCompat.CATEGORY_MESSAGE) .setSmallIcon(R.drawable.gdg_notification_icon) .setContentTitle(remoteMessage.getNotification().getTitle()) .setContentText(remoteMessage.getNotification().getBody()) .setAutoCancel(true) .setSound(defaultURI) .setContentIntent(intent1); NotificationManager manager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)); if (manager != null) { manager.notify(23,builder.build()); } }
public void onIncomingCallRinging() { int ringerMode = NotificationUtil.getRingerMode(this); if(ringerMode != AudioManager.RINGER_MODE_SILENT){ if(ringerMode == AudioManager.RINGER_MODE_VIBRATE){ mVibrator = (Vibrator) RongContext.getInstance().getSystemService(Context.VIBRATOR_SERVICE); mVibrator.vibrate(new long[] {500, 1000}, 0); } else { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); mMediaPlayer = new MediaPlayer(); try { mMediaPlayer.setDataSource(this, uri); mMediaPlayer.setLooping(true); mMediaPlayer.prepare(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } } } }
public void notificationAviso(int num) { Intent i = new Intent(getBaseContext(), getBaseContext().getClass()); CharSequence contentTitle = "Grabando actividad"; CharSequence contentText = "Hemos terminado una parte. Podemos continuar."; if(num == NUM_ARCHIVOS_CREAR){ contentText = "Hemos terminado."; } PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification noti = new NotificationCompat.Builder(this) .setContentIntent(pendingIntent) .setContentTitle(contentTitle) .setContentText(contentText) .setSmallIcon(R.drawable.ico_activ) .setVibrate(new long[] {100, 250, 100, 500}) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .build(); nm.notify(1, noti); }
@SuppressWarnings("deprecation") private void sendNotification(String messageBody) { Intent intent = new Intent(this, LModActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 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(this.getString(R.string.app_name)) .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
private static void buildNotification(String message, PendingIntent contentIntent, String name, Context mContext) { NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); Uri alarmSound = RingtoneManager .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(name) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setContentText(message) .setPriority(NotificationCompat.PRIORITY_HIGH) .setSound(alarmSound).setOnlyAlertOnce(true).setTicker(message) .setWhen(System.currentTimeMillis()).setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(ApplicationProps.NOTIFICATION_ID, mBuilder.build()); }
private void initSeekBar(SeekBar seekBar, Uri defaultUri) { seekBar.setMax(mAudioManager.getStreamMaxVolume(mStreamType)); mOriginalStreamVolume = mAudioManager.getStreamVolume(mStreamType); seekBar.setProgress(mOriginalStreamVolume); seekBar.setOnSeekBarChangeListener(this); // TODO: removed in MM, find different approach mContext.getContentResolver().registerContentObserver( System.getUriFor("volume_ring"), false, mVolumeObserver); if (defaultUri == null) { if (mStreamType == AudioManager.STREAM_RING) { defaultUri = Settings.System.DEFAULT_RINGTONE_URI; } else if (mStreamType == AudioManager.STREAM_NOTIFICATION) { defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI; } else { defaultUri = Settings.System.DEFAULT_ALARM_ALERT_URI; } } mRingtone = RingtoneManager.getRingtone(mContext, defaultUri); if (mRingtone != null) { mRingtone.setStreamType(mStreamType); } }
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. */ private void sendNotification(RemoteMessage.Notification messageBody) { System.out.println("SEND NOTIFICATION CALLED"); Intent intent = new Intent(this, SplashActivity.class); System.out.println(messageBody.getBody()); 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(messageBody.getTitle()) .setContentText(messageBody.getBody()) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
private void sendNotification(String title, String messageBody, int notificationId) { 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.logo_white) .setContentTitle(title) .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId, notificationBuilder.build()); }
private void sendNotification(String text) { Intent intent = new Intent(this, MapsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("Bloeddonatie") .setContentText(text) .setAutoCancel(true) .setSound(notificationSound) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notifiBuilder.build()); }
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. */ private void sendNotification(String messageBody) { Intent intent = new Intent(this, GroupChannelActivity.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("Quire") .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { // default sms app dialog result case DEFAULT_SMS_APP: if (resultCode == Activity.RESULT_OK) { Permissions.invalidateCache(); } // reload list reloadListViewItems(); break; // ringtone picker dialog results default: // get ringtone url Uri uri = null; if (resultCode == Activity.RESULT_OK && data != null) { uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); } // save url as settings property value setRingtoneUri(requestCode, uri); break; } }
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, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(android.R.drawable.ic_menu_add) .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()); }
private void showNotification(Game game) { DateTime dateTime = new DateTime(game.getGameDateTime(), Constants.DATE.VEGAS_TIME_ZONE).plusSeconds(60); if (dateTime.isAfterNow()) { String ringtonePath = MultiProcessPreference.getDefaultSharedPreferences().getString(mContext.getString(R.string.key_notification_ringtone), null); Uri soundUri; if (ringtonePath == null) { soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } else { soundUri = Uri.parse(ringtonePath); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.ic_league_white_24px) .setContentTitle("Game Started - " + game.getLeagueType().getAcronym()) .setContentText(mContext.getString(R.string.team_vs_team_full, game.getFirstTeam().getCity(), game.getSecondTeam().getCity())) .setSound(soundUri); // Sets an ID for the notification int mNotificationId = createHash(game.getFirstTeam().getCity() + game.getSecondTeam().getCity()); // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, mBuilder.build()); } }
private void showNotification(Game game, IntermediateResult result) { DateTime dateTime = new DateTime(game.getGameDateTime(), Constants.DATE.VEGAS_TIME_ZONE).plusSeconds(60); if (dateTime.isAfterNow()) { String ringtonePath = MultiProcessPreference.getDefaultSharedPreferences().getString(mContext.getString(R.string.key_notification_ringtone), null); Uri soundUri; if (ringtonePath == null) { soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); } else { soundUri = Uri.parse(ringtonePath); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.ic_league_white_24px) .setContentTitle("Game Started - " + result.getTeamScore(game.getFirstTeam()) + " - " + result.getTeamScore(game.getSecondTeam())) .setContentText(mContext.getString(R.string.team_vs_team_full, game.getFirstTeam().getCity(), game.getSecondTeam().getCity())) .setSound(soundUri); // Sets an ID for the notification int mNotificationId = createHash(game.getFirstTeam().getCity() + game.getSecondTeam().getCity()); // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(mNotificationId, mBuilder.build()); } }
private void sendNotification(String messageBody) { Intent intent = new Intent(this, StartingActivity.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 = (NotificationCompat.Builder) new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.bee_logo_app) .setContentTitle("Alert") .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
private void PlannedNotifyUser(Context context, String title, String description) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(title) .setContentText(description); mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification notification = mBuilder.build(); notification.contentIntent = intent; // .setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(nID, notification); nID++; }
private void addNotification(Context context, Data data) { String commentText = "", gradeText = ""; String notifText = ""; if (data.addedComments > 0) commentText = data.addedComments + " new comments"; if (data.addedGradings > 0) gradeText = data.addedGradings + " new ratings"; Log.d("NOTIFICATION","" + System.currentTimeMillis()); Log.d("NOTIFICATION","NOTIF: " + commentText + gradeText); if (commentText.equals("") && gradeText.equals("")) return; else if(!commentText.equals("") && !gradeText.equals("")) notifText = commentText +" & " + gradeText + " received!"; else notifText = commentText + gradeText + " received!"; NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setContentTitle("Updates on your LD entry") .setContentText(notifText) .setSmallIcon(R.drawable.ic_notif) .setPriority(Notification.PRIORITY_HIGH) .setAutoCancel(true) .setCategory(Notification.CATEGORY_SOCIAL) .setSound( RingtoneManager.getActualDefaultRingtoneUri( context, RingtoneManager.TYPE_NOTIFICATION)); Intent intent = new Intent(context.getApplicationContext(), MainActivity.class); PendingIntent resultPendingIntent = PendingIntent. getActivity( context, 12, intent, PendingIntent.FLAG_ONE_SHOT); notificationBuilder.setContentIntent(resultPendingIntent); NotificationManager manager = (NotificationManager) context. getSystemService( Context.NOTIFICATION_SERVICE); manager.notify(234,notificationBuilder.build()); }
private void showCountDownNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_timer) .setContentTitle(getString(R.string.app_name)) .setContentText("You Worked Hard. Have Fun") .setLights(Color.RED, 1000, 1000) .setVibrate(new long[]{0, 400, 250, 400}) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); NotificationManager mNotifyMgr = (NotificationManager) this.getSystemService(Context .NOTIFICATION_SERVICE); mNotifyMgr.notify(1, mBuilder.build()); }
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary( index >= 0 ? listPreference.getEntries()[index] : null); } else if (preference instanceof RingtonePreference) { // For ringtone preferences, look up the correct display value // using RingtoneManager. if (TextUtils.isEmpty(stringValue)) { // Empty values correspond to 'silent' (no ringtone). preference.setSummary(R.string.pref_ringtone_silent); } else { Ringtone ringtone = RingtoneManager.getRingtone( preference.getContext(), Uri.parse(stringValue)); if (ringtone == null) { // Clear the summary if there was a lookup error. preference.setSummary(null); } else { // Set the summary to reflect the new ringtone display // name. String name = ringtone.getTitle(preference.getContext()); preference.setSummary(name); } } } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
public void playNotificationSound() { try { Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + mContext.getPackageName() + "/raw/notification"); Ringtone r = RingtoneManager.getRingtone(mContext, alarmSound); r.play(); } catch (Exception e) { e.printStackTrace(); } }
private Notification createNotification(long dateNoteCreated) { Intent intent = new Intent(context, MainActivity.class) .putExtra(INTENT_EXTRA_DATE_NOTE_CREATED, dateNoteCreated) .setAction(Long.toString(System.currentTimeMillis())); return new NotificationCompat.Builder(context) .setContentTitle(context.getString(R.string.reminding)) .setContentText(context.getString(R.string.tap_to_see)) .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) .setAutoCancel(true) .setSmallIcon(R.drawable.ic_notifications_white_48dp) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .build(); }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String value = (String) newValue; if (TextUtils.isEmpty(value)) { preference.setSummary(R.string.preferences__silent); } else { Ringtone tone = RingtoneManager.getRingtone(getActivity(), Uri.parse(value)); if (tone != null) { preference.setSummary(tone.getTitle(getActivity())); } } return true; }