本文整理了Java中android.media.RingtoneManager
类的一些代码示例,展示了RingtoneManager
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RingtoneManager
类的具体详情如下:
包路径:android.media.RingtoneManager
类名称:RingtoneManager
暂无
代码示例来源:origin: LawnchairLauncher/Lawnchair
.setContentText(context.getResources().getString(R.string.update_available))
.setSmallIcon(R.drawable.ic_lawnchair)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setVibrate(new long[]{0, 100, 100, 100})
.setAutoCancel(true)
代码示例来源:origin: aporter/coursera-android
private void playRingtone(int newRingtoneType) {
Ringtone newRingtone = RingtoneManager.getRingtone(
getApplicationContext(), RingtoneManager
.getDefaultUri(newRingtoneType));
if (null != mCurrentRingtone && mCurrentRingtone.isPlaying())
mCurrentRingtone.stop();
mCurrentRingtone = newRingtone;
if (null != newRingtone) {
mCurrentRingtone.play();
postStopRingtoneMessage();
}
}
代码示例来源:origin: gotev/android-upload-service
private void setRingtone(NotificationCompat.Builder notification) {
if (params.notificationConfig.isRingToneEnabled() && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
Uri sound = RingtoneManager.getActualDefaultRingtoneUri(service, RingtoneManager.TYPE_NOTIFICATION);
notification.setSound(sound);
}
}
代码示例来源:origin: NightscoutFoundation/xDrip
public static boolean isPathRingtone(Context context, String path) {
if(path == null) {
return false;
}
if(path.length() == 0) {
return false;
}
Ringtone ringtone = RingtoneManager.getRingtone(context, Uri.parse(path));
if(ringtone == null) {
return false;
}
return true;
}
代码示例来源:origin: stackoverflow.com
RingtoneManager ringtoneManager = new RingtoneManager(ActivityName.this);
ringtoneManager.setType(AudioManager.STREAM_NOTIFICATION);
Cursor c = ringtoneManager.getCursor();
Ringtone ringtone = ringtoneManager.getRingtone(index);
Ringtone ringtone.setStreamType(AudioManager.STREAM_NOTIFICATION);
if(ringtone != null && ringtoneManager.getRingtoneUri(position) != null){
ringtone.play();
}
代码示例来源:origin: ywwynm/EverythingDone
private static boolean isFileRingtone(RingtoneManager ringtoneManager, Uri uri) {
return uri != RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
&& ringtoneManager.getRingtonePosition(uri) == -1;
}
代码示例来源:origin: consp1racy/android-support-preference
private static void peek(@NonNull Context context, @NonNull Uri uri) {
if (Settings.AUTHORITY.equals(uri.getAuthority())) {
final int type = RingtoneManager.getDefaultType(uri);
// This can throw a SecurityException.
final Uri actualUri = RingtoneManager.getActualDefaultRingtoneUri(context, type);
if (actualUri != null) {
// Actual Uri may be null on Android 4 emulators, where there are no ringtones.
// Plus silent default ringtone sounds like a valid case.
peek(context, actualUri);
}
return;
}
// This can throw a SecurityException.
final ContentResolver res = context.getContentResolver();
final Cursor cursor = res.query(uri, COLUMNS, null, null, null);
if (cursor != null) {
cursor.close();
}
}
代码示例来源:origin: dakhnod/Meshenger
private void ringPhone(){
int ringerMode = ((AudioManager) getSystemService(AUDIO_SERVICE)).getRingerMode();
if(ringerMode == AudioManager.RINGER_MODE_SILENT) return;
vibrator = ((Vibrator) getSystemService(VIBRATOR_SERVICE));
long[] pattern = {1500, 800, 800, 800};
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
VibrationEffect vibe = VibrationEffect.createWaveform(pattern, 0);
vibrator.vibrate(vibe);
}else{
vibrator.vibrate(pattern, 0);
}
if(ringerMode == AudioManager.RINGER_MODE_VIBRATE) return;
ringtone = RingtoneManager.getRingtone(this, RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE));
ringtone.play();
}
代码示例来源:origin: stackoverflow.com
/**
* Play ring tone.
*
* @param ringToneTitle the ring tone title
*/
void playRingTone(String ringToneTitle) {
RingtoneManager ringtoneManager = new RingtoneManager(
getApplicationContext());
ringtoneManager.setType(RingtoneManager.TYPE_RINGTONE);
int length = ringtoneManager.getCursor().getCount();
for (int i = 0; i < length; i++) {
Ringtone mRingtone = ringtoneManager.getRingtone(i);
if (mRingtone != null) {
Log.d("ringtoneTitle ", mRingtone.getTitle(getApplicationContext()));
if(ringToneTitle.equalsIgnoreCase(mRingtone
.getTitle(getApplicationContext())) {
mRingtone.play();
}
}
}
}
代码示例来源:origin: jamorham/xDrip-plus
public static boolean isPathRingtone(Context context, String path) {
if(path == null) {
return false;
}
if(path.length() == 0) {
return false;
}
Ringtone ringtone = RingtoneManager.getRingtone(context, Uri.parse(path));
if(ringtone == null) {
return false;
}
return true;
}
代码示例来源:origin: stackoverflow.com
ArrayAdapter<RingtoneObject> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RingtoneManager ringtoneMgr = new RingtoneManager(this);
ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);
Cursor alarmsCursor = ringtoneMgr.getCursor();
int alarmsCount = alarmsCursor.getCount();
RingtoneObject[] alarms = new RingtoneObject[alarmsCount];
int index = 0;
while(alarmsCursor.moveToNext()) {
alarms[index] = new RingtoneObject(ringtoneMgr.getRingtone(index).getTitle(this), ringtoneMgr.getRingtoneUri(index));
index++;
}
alarmsCursor.close();
adapter = new ArrayAdapter<MainActivity.RingtoneObject>(this, android.R.layout.simple_list_item_1, alarms);
setListAdapter(adapter);
getListView().setOnItemClickListener(this);
}
代码示例来源:origin: LanSoSdk/LanSoEditor_common
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)
&& Settings.AUTHORITY.equals(uri.getAuthority())) {
uri = RingtoneManager.getActualDefaultRingtoneUri(context,
RingtoneManager.getDefaultType(uri));
if (uri == null) {
throw new FileNotFoundException("Failed to resolve default ringtone");
代码示例来源:origin: chat-sdk/chat-sdk-android
public void createMessageNotification(final Context context, Intent resultIntent, String userEntityID, String title, String message) {
int pushIcon = ChatSDK.config().pushNotificationImageDefaultResourceId;
if(pushIcon <= 0) {
pushIcon = R.drawable.icn_72_push_mask;
}
final int smallPushIcon = pushIcon;
final Bitmap largePushIcon = BitmapFactory.decodeResource(context.getResources(), smallPushIcon);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (userEntityID != null && !userEntityID.isEmpty()) {
User user = StorageManager.shared().fetchUserWithEntityID(userEntityID);
if (user != null) {
ImageBuilder.bitmapForURL(context, user.getAvatarURL()).subscribe((bitmap, throwable) -> {
if (throwable != null) {
ChatSDK.logError(throwable);
}
if (bitmap == null) {
bitmap = largePushIcon;
}
createAlertNotification(context, resultIntent, title, message, bitmap, smallPushIcon, alarmSound, -1);
});
} else {
createAlertNotification(context, resultIntent, title, message, largePushIcon, smallPushIcon, alarmSound, -1);
}
}
}
代码示例来源:origin: rajeeviiit/AndroidProject
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Alarm! Wake up! Wake up!", Toast.LENGTH_LONG).show();
Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if (alarmUri == null)
{
alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
Ringtone ringtone = RingtoneManager.getRingtone(context, alarmUri);
ringtone.play();
}
}
代码示例来源:origin: consp1racy/android-support-preference
@Nullable
private Ringtone getRingtone() {
if (mRingtone == null) {
final Ringtone ringtone = RingtoneManager.getRingtone(mContext, mUri);
if (ringtone != null) {
if (mStreamType != STREAM_NULL) {
ringtone.setStreamType(mStreamType);
}
}
mRingtone = ringtone;
}
return mRingtone;
}
代码示例来源:origin: stackoverflow.com
public void getRingtones( )
{
RingtoneManager ringtoneMgr = new RingtoneManager(this);
ringtoneMgr.setType(RingtoneManager.TYPE_ALL);
Cursor alarmsCursor = ringtoneMgr.getCursor();
int alarmsCount = alarmsCursor.getCount();
if (alarmsCount == 0 && !alarmsCursor.moveToFirst())
{
}
else
{
ringtonesStrings = new String[alarmsCount];
ringtonesUris = new String[alarmsCount];
while(!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
int currentPosition = alarmsCursor.getPosition();
rintonesStrings[currentPosition] = ringtoneMgr.getRingtone(currentPosition).getTitle(getApplicationContext());
ringtonesUris[currentPosition] = ringtoneMgr.getRingtoneUri(currentPosition).toString();
}
//alarmsCursor.close();
}
}
代码示例来源:origin: LanSoSdk/LanSoEditor_advance
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)
&& Settings.AUTHORITY.equals(uri.getAuthority())) {
uri = RingtoneManager.getActualDefaultRingtoneUri(context,
RingtoneManager.getDefaultType(uri));
if (uri == null) {
throw new FileNotFoundException("Failed to resolve default ringtone");
代码示例来源:origin: geniusgithub/AndroidDialer
@Override
protected Uri onRestoreRingtone() {
return RingtoneManager.getActualDefaultRingtoneUri(getContext(), getRingtoneType());
}
}
代码示例来源:origin: aws-amplify/aws-sdk-android
setContentIntent.invoke(notificationBuilder, contentIntent);
if (android.os.Build.VERSION.SDK_INT < ANDROID_OREO) {
final Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
setSoundMethod.invoke(notificationBuilder, defaultSoundUri);
代码示例来源:origin: openMF/mobile-wallet
public void playNotificationSound() {
try {
// Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
// + "://" + mContext.getPackageName() + "/raw/notification");
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(mContext, defaultSoundUri);
r.play();
} catch (Exception e) {
Log.d(TAG, "playNotificationSound: " + e.getMessage());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!