List of usage examples for android.media RingtoneManager TYPE_RINGTONE
int TYPE_RINGTONE
To view the source code for android.media RingtoneManager TYPE_RINGTONE.
Click Source Link
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();//from w ww . j a v a 2 s . c o m 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:nl.hnogames.domoticz.Utils.NotificationUtil.java
public static void sendSimpleNotification(String title, String text, final Context context) { if (UsefulBits.isEmpty(title) || UsefulBits.isEmpty(text) || context == null) return;/*from w w w. ja v a 2 s.c om*/ if (prefUtil == null) prefUtil = new SharedPrefUtil(context); prefUtil.addUniqueReceivedNotification(text); prefUtil.addLoggedNotification(new SimpleDateFormat("yyyy-MM-dd hh:mm ").format(new Date()) + text); List<String> suppressedNot = prefUtil.getSuppressedNotifications(); List<String> alarmNot = prefUtil.getAlarmNotifications(); try { if (prefUtil.isNotificationsEnabled() && suppressedNot != null && !suppressedNot.contains(text)) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.domoticz_white) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher)) .setContentTitle(alarmNot != null && alarmNot.contains(text) ? context.getString(R.string.alarm) + ": " + title : title) .setContentText(alarmNot != null && alarmNot.contains(text) ? context.getString(R.string.alarm) + ": " + text : text) .setGroupSummary(true).setGroup(GROUP_KEY_NOTIFICATIONS).setAutoCancel(true); if (!prefUtil.OverWriteNotifications()) NOTIFICATION_ID = text.hashCode(); if (prefUtil.getNotificationVibrate()) builder.setDefaults(NotificationCompat.DEFAULT_VIBRATE); if (!UsefulBits.isEmpty(prefUtil.getNotificationSound())) builder.setSound(Uri.parse(prefUtil.getNotificationSound())); Intent targetIntent = new Intent(context, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); if (prefUtil.isNotificationsEnabled() && alarmNot != null && alarmNot.contains(text)) { Intent stopAlarmIntent = new Intent(context, StopAlarmButtonListener.class); PendingIntent pendingAlarmIntent = PendingIntent.getBroadcast(context, 78578, stopAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(android.R.drawable.ic_delete, "Stop", pendingAlarmIntent); } if (prefUtil.showAutoNotifications()) { builder.extend(new NotificationCompat.CarExtender() .setUnreadConversation(getUnreadConversation(context, text))); } NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, builder.build()); if (prefUtil.isNotificationsEnabled() && alarmNot != null && alarmNot.contains(text)) { Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); if (alert == null) { alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); } if (alert != null) { Intent ringtoneServiceStartIntent = new Intent(context, RingtonePlayingService.class); ringtoneServiceStartIntent.putExtra("ringtone-uri", alert.toString()); context.startService(ringtoneServiceStartIntent); if (prefUtil.getAlarmTimer() > 0) { Thread.sleep(prefUtil.getAlarmTimer() * 1000); Intent stopIntent = new Intent(context, RingtonePlayingService.class); context.stopService(stopIntent); } } } } } catch (Exception ex) { Log.i("NOTIFY", ex.getMessage()); } }
From source file:org.cyanogenmod.theme.chooser.AudiblePreviewFragment.java
private void loadAudibles() { mContent.removeAllViews();//from ww w. j a v a2s .co m if (ThemeConfig.SYSTEM_DEFAULT.equals(mPkgName)) { loadSystemAudible(RingtoneManager.TYPE_ALARM); loadSystemAudible(RingtoneManager.TYPE_NOTIFICATION); loadSystemAudible(RingtoneManager.TYPE_RINGTONE); } else { try { final Context themeCtx = getActivity().createPackageContext(mPkgName, 0); PackageInfo pi = getActivity().getPackageManager().getPackageInfo(mPkgName, 0); loadThemeAudible(themeCtx, RingtoneManager.TYPE_ALARM, pi); loadThemeAudible(themeCtx, RingtoneManager.TYPE_NOTIFICATION, pi); loadThemeAudible(themeCtx, RingtoneManager.TYPE_RINGTONE, pi); } catch (PackageManager.NameNotFoundException e) { return; } } }
From source file:com.amazon.rvspeedtest.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); Uri uriSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("Alexa Phone Finder") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg).setSound(uriSound) .setVibrate(new long[] { 3000, 1000, 3000, 1000, 3000, 1000, 3000 }) .setLights(Color.RED, 3000, 3000).setCategory(Notification.CATEGORY_ALARM); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:org.cyanogenmod.theme.chooser.AudiblePreviewFragment.java
private void loadThemeAudible(Context themeCtx, int type, PackageInfo pi) { AssetManager assetManager = themeCtx.getAssets(); String assetPath;//w ww .j a v a 2 s . c om switch (type) { case RingtoneManager.TYPE_ALARM: assetPath = "alarms"; break; case RingtoneManager.TYPE_NOTIFICATION: assetPath = "notifications"; break; case RingtoneManager.TYPE_RINGTONE: assetPath = "ringtones"; break; default: assetPath = null; break; } if (assetPath != null) { try { String[] assetList = assetManager.list(assetPath); if (assetList != null && assetList.length > 0) { AssetFileDescriptor afd = assetManager.openFd(assetPath + File.separator + assetList[0]); MediaPlayer mp = initAudibleMediaPlayer(afd, type); if (mp != null) { addAudibleToLayout(type, mp); } } } catch (IOException e) { mMediaPlayers.put(type, null); } } }
From source file:com.rks.musicx.misc.utils.Helper.java
/** * Set Ringtone//www . j av a 2 s . com * * @param context * @param path */ private static void setRingtone(Context context, String path) { if (path == null) { return; } File file = new File(path); ContentValues contentValues = new ContentValues(); contentValues.put(MediaColumns.DATA, file.getAbsolutePath()); String filterName = path.substring(path.lastIndexOf("/") + 1); contentValues.put(MediaColumns.TITLE, filterName); contentValues.put(MediaColumns.MIME_TYPE, "audio/mp3"); contentValues.put(MediaColumns.SIZE, file.length()); contentValues.put(Media.IS_RINGTONE, true); Uri uri = MediaStore.Audio.Media.getContentUriForPath(path); Cursor cursor = context.getContentResolver().query(uri, null, MediaStore.MediaColumns.DATA + "=?", new String[] { path }, null); if (cursor != null && cursor.moveToFirst() && cursor.getCount() > 0) { String id = cursor.getString(0); contentValues.put(MediaStore.Audio.Media.IS_RINGTONE, true); context.getContentResolver().update(uri, contentValues, MediaStore.MediaColumns.DATA + "=?", new String[] { path }); Uri newuri = ContentUris.withAppendedId(uri, Long.valueOf(id)); try { RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newuri); } catch (Throwable t) { t.printStackTrace(); } cursor.close(); } }
From source file:org.wso2.iot.agent.AlertActivity.java
/** * This method is used to start ringing the phone. *//*from w w w . j ava 2 s. c o m*/ @TargetApi(21) private void startRing() { if (audio != null) { ringerMode = audio.getRingerMode(); ringerVolume = audio.getStreamVolume(AudioManager.STREAM_RING); audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL); audio.setStreamVolume(AudioManager.STREAM_RING, audio.getStreamMaxVolume(AudioManager.STREAM_RING), AudioManager.FLAG_PLAY_SOUND); defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE); if (defaultRingtoneUri != null) { defaultRingtone = RingtoneManager.getRingtone(this, defaultRingtoneUri); if (defaultRingtone != null) { if (deviceInfo.getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes attributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build(); defaultRingtone.setAudioAttributes(attributes); } else { defaultRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION); } defaultRingtone.play(); } } } }
From source file:com.android.contacts.editor.EditorUiUtils.java
/** * Returns a ringtone URI, based on the string and version #. *//*from ww w .j a v a 2s .c o m*/ public static Uri getRingtoneUriFromString(String str, int currentVersion) { if (str != null) { if (isNewerThanM(currentVersion) && TextUtils.isEmpty(str)) return null; return Uri.parse(str); } return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); }
From source file:org.wso2.emm.agent.AlertActivity.java
/** * This method is used to start ringing the phone. *///from www .j a v a2s . co m @TargetApi(21) private void startRing() { if (audio != null) { audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL); audio.setStreamVolume(AudioManager.STREAM_RING, audio.getStreamMaxVolume(AudioManager.STREAM_RING), AudioManager.FLAG_PLAY_SOUND); defaultRingtoneUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE); if (defaultRingtoneUri != null) { defaultRingtone = RingtoneManager.getRingtone(this, defaultRingtoneUri); if (defaultRingtone != null) { if (deviceInfo.getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes attributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build(); defaultRingtone.setAudioAttributes(attributes); } else { defaultRingtone.setStreamType(AudioManager.STREAM_NOTIFICATION); } defaultRingtone.play(); } } } }
From source file:org.cyanogenmod.theme.chooser.AudiblePreviewFragment.java
private void addAudibleToLayout(int type, MediaPlayer mp) { View view = View.inflate(getActivity(), R.layout.audible_preview_item, null); TextView tv = (TextView) view.findViewById(R.id.audible_name); switch (type) { case RingtoneManager.TYPE_ALARM: tv.setText(R.string.alarm_label); break;/*from ww w . j a v a 2 s . c o m*/ case RingtoneManager.TYPE_NOTIFICATION: tv.setText(R.string.notification_label); break; case RingtoneManager.TYPE_RINGTONE: tv.setText(R.string.ringtone_label); break; } ImageView iv = (ImageView) view.findViewById(R.id.btn_play_pause); iv.setTag(mp); iv.setOnClickListener(mPlayPauseClickListener); mContent.addView(view, ITEM_LAYOUT_PARAMS); }