android.media.RingtoneManager.getDefaultUri()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(111)

本文整理了Java中android.media.RingtoneManager.getDefaultUri方法的一些代码示例,展示了RingtoneManager.getDefaultUri的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RingtoneManager.getDefaultUri方法的具体详情如下:
包路径:android.media.RingtoneManager
类名称:RingtoneManager
方法名:getDefaultUri

RingtoneManager.getDefaultUri介绍

暂无

代码示例

代码示例来源: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: 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: 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: be.e_contract.jwatchdog/jwatchdog-android

private Uri getAlarmUri() {
  Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
  if (null != uri) {
    return uri;
  }
  return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALL);
}

代码示例来源:origin: kevalpatel2106/android-ringtone-picker

/**
 * Get the system selected default alarm tone.
 *
 * @return Uri of the selected alarm tone. You may need android.permission.READ_EXTERNAL_STORAGE
 * permission to read the ringtone selected from the external storage.
 */
@Nullable
public static Uri getSystemAlarmTone() {
  return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
}

代码示例来源:origin: kevalpatel2106/android-ringtone-picker

/**
 * Get the system selected default notification tone.
 *
 * @return Uri of the selected notification tone. You may need android.permission.READ_EXTERNAL_STORAGE
 * permission to read the ringtone selected from the external storage.
 */
@Nullable
public static Uri getSystemNotificationTone() {
  return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}

代码示例来源:origin: kevalpatel2106/android-ringtone-picker

/**
 * Get the system selected default ringtone.
 *
 * @return Uri of the selected ringtone. You may need android.permission.READ_EXTERNAL_STORAGE
 * permission to read the ringtone selected from the external storage.
 */
@Nullable
public static Uri getSystemRingtoneTone() {
  return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
}

代码示例来源:origin: stackoverflow.com

RingtoneManager ringtoneManager = new RingtoneManager(context);
Uri defaultSoundUri = ringtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
final Notification.Builder builder = new Notification.Builder(context)
  ...
  .setSound(defaultSoundUri);

代码示例来源:origin: AEFeinstein/mtg-familiar

public static synchronized String getTimerSound(@Nullable Context context) {
  if (null == context) {
    return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString();
  }
  return PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.key_timerSound), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString());
}

代码示例来源:origin: sylvek/itracing2

public static String getRingtone(Context context, String address, String source)
{
  final Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
  return getSharedPreferences(context, address).getString(RINGTONE + "_" + source, sound.toString());
}

代码示例来源: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: NordicSemiconductor/Android-nRF-Toolbox

private void initializeAlarm() {
  mDevicesWithAlarm = new LinkedList<>();
  mMediaPlayer = new MediaPlayer();
  mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
  mMediaPlayer.setLooping(true);
  mMediaPlayer.setVolume(1.0f, 1.0f);
  try {
    mMediaPlayer.setDataSource(this, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
  } catch (final IOException e) {
    Log.e(TAG, "Initialize Alarm failed: ", e);
  }
}

代码示例来源: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());
    }
  }
}

代码示例来源:origin: MCMrARM/revolution-irc

public static String getValueDisplayString(Context context, Uri uri) {
  if (uri == null)
    return context.getString(R.string.value_none);
  if (uri.equals(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)))
    return context.getString(R.string.value_default);
  Ringtone ret = RingtoneManager.getRingtone(context, uri);
  if (ret != null)
    return ret.getTitle(context);
  return null;
}

代码示例来源:origin: pimpimmi/LibreAlarm

private void startAlarm(Status status) {
  boolean usePhoneAlarm = PreferenceManager.getDefaultSharedPreferences(this)
      .getBoolean(getString(R.string.pref_key_phone_alarm), false);
  if (usePhoneAlarm) {
    if (mAlarmPlayer == null) {
      mAlarmPlayer = MediaPlayer.create(
          this, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
    }
    mAlarmPlayer.start();
  }
  startActivity(MainActivity.buildAlarmIntent(this, status));
}

代码示例来源:origin: consp1racy/android-support-preference

public boolean canPlayDefaultRingtone(final @NonNull Context context) {
  final Uri defaultUri = RingtoneManager.getDefaultUri(mRingtoneType);
  final SafeRingtone ringtone = SafeRingtone.obtain(context, defaultUri);
  try {
    return ringtone.canPlay();
  } finally {
    ringtone.stop();
  }
}

代码示例来源:origin: andstatus/andstatus

/**
   * See http://stackoverflow.com/questions/4441334/how-to-play-an-android-notification-sound/9622040
   */
  private static void beep(Context context) {
    try {
      Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
      Ringtone r = RingtoneManager.getRingtone(context, notification);
      r.play();
    } catch (Exception e) {
      MyLog.e("beep", e);
    }        
  }
}

代码示例来源:origin: googlesamples/android-FindMyPhone

@Override
public void onCreate() {
  super.onCreate();
  mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
  mOrigVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
  mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
  mAlarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
  mMediaPlayer = new MediaPlayer();
}

代码示例来源:origin: UdacityAndroidBasicsScholarship/wmn-safety

@Override
  public void onClick(View v) {

    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    Ringtone ringtone = RingtoneManager.getRingtone(getActivity(),notification);
    ringtone.play();
  }
}

相关文章