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

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

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

RingtoneManager.getRingtoneUri介绍

暂无

代码示例

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

RingtoneManager ringtoneMgr = new RingtoneManager(this);
ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);
Cursor alarmsCursor = ringtoneMgr.getCursor();
int alarmsCount = alarmsCursor.getCount();
if (alarmsCount == 0 && !alarmsCursor.moveToFirst()) {
  return null;
}
Uri[] alarms = new Uri[alarmsCount];
while(!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
  int currentPosition = alarmsCursor.getPosition();
  alarms[currentPosition] = ringtoneMgr.getRingtoneUri(currentPosition);
}
alarmsCursor.close();
return alarms;

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

RingtoneManager mRing= new RingtoneManager(RingtoneActivity.this); 
int mNumberOfRingtones = mRing.getCursor().getCount();
Uri mRingToneUri = mRing.getRingtoneUri((int) (Math.random() * mNumberOfRingtones));

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

RingtoneManager rm = new RingtoneManager(context);
 Random random = new Random();
 int i = rm.getRingtonePosition(RingtoneManager
     .getActualDefaultRingtoneUri(context,
         RingtoneManager.TYPE_RINGTONE));
 MyApplication.APPLICATION_SHARED_PREFERENCE.edit()
     .putInt(MyConstants.PHONE_RINGTONE_NUMBER, i).commit();
 int chanegToneNumber;
 Cursor cursor = rm.getCursor();
 while (true) {
   chanegToneNumber = random.nextInt(cursor.getCount());
   if (chanegToneNumber != i)
     break;
 }
 Log.d(TAG, "Tone: " + i);
 Log.d(TAG, "Tone total: " + cursor.getCount());
 while (cursor.moveToNext()) {
   if (i == cursor.getInt(cursor
       .getColumnIndex(MediaStore.MediaColumns._ID))) {
     RingtoneManager.setActualDefaultRingtoneUri(context,
         RingtoneManager.TYPE_RINGTONE,
         rm.getRingtoneUri(chanegToneNumber));
     break;
   }
 }

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

public Map<String, String> getNotifications() {
  RingtoneManager manager = new RingtoneManager(this);
  manager.setType(RingtoneManager.TYPE_NOTIFICATION);
  Cursor cursor = manager.getCursor();

  Map<String, Uri> list = new HashMap<>();
  while (cursor.moveToNext()) {
    String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
    Uri notificationUri = manager.getRingtoneUri(cursor.getPosition());

    list.put(notificationTitle, notificationUri);
  }

  return list;
}

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

public void listRingtones() {
 RingtoneManager manager = new RingtoneManager(this);
 manager.setType(RingtoneManager.TYPE_RINGTONE);
 Cursor cursor = manager.getCursor();
 while (cursor.moveToNext()) {
  String title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
  Uri ringtoneURI = manager.getRingtoneUri(cursor.getPosition());
  // Do something with the title and the URI of ringtone
 }
}

代码示例来源: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: 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: werbhelius/MyCalendarDemo

@Override
  public void onItemClick(View view, String data,int position) {
    Toast.makeText(SetAlarmToneActivity.this, data + "-" + position, Toast.LENGTH_SHORT).show();
    toneName = data;
    RingtoneManager rm = new RingtoneManager(SetAlarmToneActivity.this);
    rm.setType(RingtoneManager.TYPE_RINGTONE);
    rm.getCursor();
    Uri ringtoneUri = rm.getRingtoneUri(position);
    tonePath = ringtoneUri.toString();
    if (mediaPlayer == null) {
      mediaPlayer = new MediaPlayer();
    } else {
      if (mediaPlayer.isPlaying())
        mediaPlayer.stop();
      mediaPlayer.reset();
    }
    try {
      mediaPlayer.setDataSource(SetAlarmToneActivity.this, ringtoneUri);
      mediaPlayer.setVolume(1f, 1f);
      mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
      mediaPlayer.setLooping(false);
      mediaPlayer.prepare();
      mediaPlayer.start();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
});

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

List<Uri> listRingtones = new ArrayList<Uri>();
int ringTypes[] = {RingtoneManager.TYPE_ALARM,
          RingtoneManager.TYPE_RINGTONE,
          RingtoneManager.TYPE_NOTIFICATION};

for (int ringType : ringTypes) {

  RingtoneManager ringtoneMgr = new RingtoneManager(this);
  ringtoneMgr.setType(ringType);
  Cursor alarmsCursor = ringtoneMgr.getCursor();
  if (alarmsCursor.getCount() == 0 && !alarmsCursor.moveToFirst()) {
    return null;
  }

  while (!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
    listRingtones.add(
          ringtoneMgr.getRingtoneUri(alarmsCursor.getPosition()));
  }

  alarmsCursor.close();
}

代码示例来源:origin: ywwynm/EverythingDone

Uri defaultUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (defaultUri == null) {
  defaultUri = rm.getRingtoneUri(0);

代码示例来源:origin: ywwynm/EverythingDone

int count = cursor.getCount();
for (int i = 0; i < count; i++) {
  sRingtoneUriList.add(manager.getRingtoneUri(i));
  sRingtoneTitleList.add(StringUtil.replaceChineseBrackets(
      manager.getRingtone(i).getTitle(context)));

代码示例来源: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: consp1racy/android-support-preference

@Override
public void onDialogClosed(boolean positiveResult) {
  // Stop playing the previous ringtone
  if (sPlayingRingtone == null) {
    mRingtoneManager.stopPreviousRingtone();
  }
  // The volume keys will control the default stream
  if (getActivity() != null) {
    getActivity().setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
  }
  if (positiveResult) {
    Uri uri;
    if (mClickedPos == mDefaultRingtonePos) {
      // Set it to the default Uri that they originally gave us
      uri = mUriForDefaultItem;
    } else if (mClickedPos == mSilentPos) {
      // A null Uri is for the 'Silent' item
      uri = null;
    } else if (mClickedPos == mUnknownPos) {
      // 'Unknown' was shown because it was persisted before showing the picker.
      // There's no change to persist, return immediately.
      return;
    } else {
      uri = mRingtoneManager.getRingtoneUri(getRingtoneManagerPosition(mClickedPos));
    }
    requireRingtonePreference().saveRingtone(uri);
  }
}

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

ringtone = mRingtoneManager.getRingtone(position);
} catch (SecurityException ex) {
  XpSupportPreferencePlugins.onError(ex, "Failed to create selected Ringtone from " + mRingtoneManager.getRingtoneUri(position) + ".");

相关文章