List of usage examples for android.media RingtoneManager getRingtone
public static Ringtone getRingtone(final Context context, Uri ringtoneUri)
From source file:org.getlantern.firetweet.preference.RingtonePreference.java
private void loadRingtones(final Context context) { final RingtoneManager manager = new RingtoneManager(context); manager.setType(RingtoneManager.TYPE_NOTIFICATION); final Cursor cur = manager.getCursor(); cur.moveToFirst();//from ww w . ja v a 2 s . c om final int count = cur.getCount(); mRingtones = new Ringtone[count + 1]; mEntries = new String[count + 1]; mValues = new String[count + 1]; final Uri default_uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); final Ringtone default_ringtone = RingtoneManager.getRingtone(context, default_uri); mRingtones[0] = default_ringtone; mEntries[0] = context.getString(R.string.default_ringtone); mValues[0] = default_uri.toString(); for (int i = 0; i < count; i++) { final Ringtone ringtone = manager.getRingtone(i); mRingtones[i + 1] = ringtone; mEntries[i + 1] = ringtone.getTitle(context); mValues[i + 1] = manager.getRingtoneUri(i).toString(); } setEntries(mEntries); setEntryValues(mValues); cur.close(); }
From source file:es.gaedr_space.puntogpsqr.QRVisorFragment.java
/** * Mtodo que se lanza cada vez que se encuentra un resultado para su manejo * * @param result que contiene el contenido del QR *//*from w w w . ja v a2s . co m*/ @Override public void handleResult(Result result) { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getActivity().getApplicationContext(), notification); r.play(); } catch (Exception e) { Log.d(TAG, getContext().getString(R.string.error_sound) + " : " + e.getMessage()); } if (transforStringToCoordinates(result.getText())) { GPS = new GPSService(getActivity()); if (GPS.canGetLocation()) { mSiteLocation.save(); DialogFragment dialog = new DialogFragment() { @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(getString(R.string.dialog_message, mSiteLocation.getLatitude(), mSiteLocation.getLongitude())); builder.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (!mSiteLocation.isEmpty()) { startActivity(mapsLauncher(mSiteLocation, GPS.getSiteLocation())); } mSiteLocation = null; dismiss(); } }); builder.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { mSiteLocation = null; dismiss(); } }); builder.setCancelable(false); return builder.create(); } @Override public void onPause() { mSiteLocation = null; super.onPause(); } @Override public void onDetach() { mSiteLocation = null; super.onDetach(); } }; dialog.show(getActivity().getSupportFragmentManager(), "dialog"); } else { showSettingsAlert(getActivity()); } } mScannerView.resumeCameraPreview(this); }
From source file:org.proninyaroslav.libretorrent.settings.AppearanceSettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final SettingsManager pref = new SettingsManager(getActivity().getApplicationContext()); String keyTheme = getString(R.string.pref_key_theme); ListPreference theme = (ListPreference) findPreference(keyTheme); int type = pref.getInt(keyTheme, Integer.parseInt(getString(R.string.pref_theme_light_value))); theme.setValueIndex(type);//w w w .j a va2 s .c o m String typesName[] = getResources().getStringArray(R.array.pref_theme_entries); theme.setSummary(typesName[type]); bindOnPreferenceChangeListener(theme); String keyTorrentFinishNotify = getString(R.string.pref_key_torrent_finish_notify); SwitchPreferenceCompat torrentFinishNotify = (SwitchPreferenceCompat) findPreference( keyTorrentFinishNotify); torrentFinishNotify.setChecked(pref.getBoolean(keyTorrentFinishNotify, true)); bindOnPreferenceChangeListener(torrentFinishNotify); String keyPlaySound = getString(R.string.pref_key_play_sound_notify); SwitchPreferenceCompat playSound = (SwitchPreferenceCompat) findPreference(keyPlaySound); playSound.setChecked(pref.getBoolean(keyPlaySound, true)); bindOnPreferenceChangeListener(playSound); final String keyNotifySound = getString(R.string.pref_key_notify_sound); Preference notifySound = findPreference(keyNotifySound); String ringtone = pref.getString(keyNotifySound, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString()); notifySound .setSummary(RingtoneManager.getRingtone(getActivity().getApplicationContext(), Uri.parse(ringtone)) .getTitle(getActivity().getApplicationContext())); /* See https://code.google.com/p/android/issues/detail?id=183255 */ notifySound.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, Settings.System.DEFAULT_NOTIFICATION_URI); String curRingtone = pref.getString(keyNotifySound, null); if (curRingtone != null) { if (curRingtone.length() == 0) { // Select "Silent" intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null); } else { intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(curRingtone)); } } else { intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Settings.System.DEFAULT_NOTIFICATION_URI); } startActivityForResult(intent, REQUEST_CODE_ALERT_RINGTONE); return true; } }); String keyLedIndicator = getString(R.string.pref_key_led_indicator_notify); SwitchPreferenceCompat ledIndicator = (SwitchPreferenceCompat) findPreference(keyLedIndicator); ledIndicator.setChecked(pref.getBoolean(keyLedIndicator, true)); bindOnPreferenceChangeListener(ledIndicator); String keyLedIndicatorColor = getString(R.string.pref_key_led_indicator_color_notify); ColorPreference ledIndicatorColor = (ColorPreference) findPreference(keyLedIndicatorColor); ledIndicatorColor.forceSetValue(pref.getInt(keyLedIndicatorColor, ContextCompat.getColor(getActivity().getApplicationContext(), R.color.primary))); bindOnPreferenceChangeListener(ledIndicatorColor); String keyVibration = getString(R.string.pref_key_vibration_notify); SwitchPreferenceCompat vibration = (SwitchPreferenceCompat) findPreference(keyVibration); vibration.setChecked(pref.getBoolean(keyVibration, true)); bindOnPreferenceChangeListener(vibration); }
From source file:com.abel.ooti.boss.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();//from www .ja v a 2s . c o m GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. sendNotification("Received: " + extras.toString()); Log.i(TAG, "Received: " + extras.toString()); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { } } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
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();/* ww w. j a v a 2s .c om*/ 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:com.cfc.needblood.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. */// ww w. j a v a 2 s.c o m 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:edu.rit.csh.androidwebnews.UpdaterService.java
/** * The IntentService calls this method from the default worker thread with * the intent that started the service. When this method returns, IntentService * stops the service, as appropriate./*from w ww . j a va 2s . c om*/ */ @Override protected void onHandleIntent(Intent intent) { Vibrator mVibrator; Uri notification; Ringtone r; SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); HttpsConnector hc = new HttpsConnector(this); int[] statuses; try { statuses = hc.getUnreadCount(); // throws all the errors // if there are WebNews new posts and that number is different than last time the update ran if (statuses[0] != 0 && statuses[0] != sharedPref.getInt("number_of_unread", 0)) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("number_of_unread", statuses[0]); editor.commit(); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(getString(R.string.app_name)); builder.setSmallIcon(R.drawable.notification_icon); builder.setAutoCancel(true); if (statuses[2] != 0) { if (statuses[2] == 1) { builder.setContentText(statuses[2] + " reply to your post"); } else { builder.setContentText(statuses[2] + " reply to your posts"); } } else if (statuses[1] != 0) { if (statuses[1] == 1) { builder.setContentText(statuses[1] + " unread post in your thread"); } else { builder.setContentText(statuses[1] + " unread posts in your thread"); } } else { if (statuses[0] == 1) { builder.setContentText(statuses[0] + " unread post"); } else { builder.setContentText(statuses[0] + " unread posts"); } } if (sharedPref.getBoolean("vibrate_service", true)) { mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); mVibrator.vibrate(500); } if (sharedPref.getBoolean("ring_service", false)) { notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } // Creates an explicit intent for an Activity in your app /* The stack builder object will contain an artificial back stack for the started Activity. This ensures that navigating backward from the Activity leads out of your application to the Home screen. */ // notification is selected Intent notificationIntent = new Intent(this, RecentActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); // Add as notification NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(0, builder.build()); } else if (statuses[0] == 0) { // if all post have been read /* if a user reads all the posts, the notification is removed */ NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.cancel(0); } } catch (InvalidKeyException e) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setContentTitle(getString(R.string.app_name)); mBuilder.setSmallIcon(R.drawable.notification_icon); mBuilder.setContentText("Invalid API Key"); mBuilder.setAutoCancel(true); Intent resultIntent = new Intent(this, SettingsActivity.class); TaskStackBuilder stackBuilder; try { stackBuilder = TaskStackBuilder.create(this); } catch (Exception e1) { return; } // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(SettingsActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); } catch (NoInternetException e) { // do nothing if there is no internet for the background service } catch (InterruptedException e) { // normally never hit } catch (ExecutionException e) { // normally never hit } }
From source file:edu.asu.cse535.assignment3.MainActivity.java
public void notifyCompletion() { try {/* ww w. ja v a 2s . c o m*/ Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
From source file:random.taiga.chat.truelecter.randomchat.ChatActivity.java
/** * Plays device's default notification sound *//*from w ww . j av a 2 s . c o m*/ public void playBeep() { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
From source file:nl.johndekroon.dma.GCMIntentService.java
@Override protected void onMessage(Context context, Intent intent) { prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); prefs.getBoolean("muteAll", false); String data = intent.getStringExtra("message"); JSONObject datajson;// ww w . j a va2 s . co m try { datajson = new JSONObject(data); String message = datajson.get("message").toString(); String type = datajson.get("type").toString(); String monitor = datajson.get("monitor").toString(); DatabaseDAO datasource = new DatabaseDAO(this); datasource.open(); //On getting a warning or an OK if (type.equals("WARNING") || type.equals("OK")) { if (prefs.getBoolean("muteAll", false) != true) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 500, 200, 200 }; // Only perform this pattern one time (-1 means "do not repeat") v.vibrate(pattern, -1); Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) { // I can't see this ever being null (as always have a default notification) but just incase // alert backup is null, using 2nd backup alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), alert); r.play(); } datasource.updateScenario(monitor, type); generateNotification(context, message); } //on receiving an error else if (type.equals("ERROR")) { System.out.println("bbbrrrrrrr brrrrrr"); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 1000, 50, 200, 50, 200, 50, 1200 }; // Only perform this pattern one time (-1 means "do not repeat") v.vibrate(pattern, -1); if (prefs.getBoolean("muteAll", false) != true) { Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) { alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), alert); r.play(); } datasource.updateScenario(monitor, type); generateNotification(context, message); } //on register, make a new scenario. else if (type.equals("REGISTER")) { datasource.createScenario(monitor); } System.out.println(intent.getStringExtra("message")); Log.i(TAG, "Received message"); //No idea why this part isn't working. It should. // if(type.equals("ERROR")) // { // displayMessage(context, message, "error"); // } // else // { displayMessage(context, message); // } } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }