本文整理了Java中android.media.RingtoneManager.getCursor
方法的一些代码示例,展示了RingtoneManager.getCursor
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RingtoneManager.getCursor
方法的具体详情如下:
包路径:android.media.RingtoneManager
类名称:RingtoneManager
方法名:getCursor
暂无
代码示例来源: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 ringtoneManager = new RingtoneManager(yourActivity);
ringtoneManager.setType(RingtoneManager.TYPE_RINGTONE);
Cursor cursor = ringtoneManager.getCursor();
while (cursor.moveToNext()) {
System.out.println(cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX));
System.out.println(cursor.getString(RingtoneManager.URI_COLUMN_INDEX));
}
代码示例来源:origin: stackoverflow.com
//Import All Ringtones
RingtoneManager rm = new RingtoneManager(UserSettingActivity.this);
rm.setType(RingtoneManager.TYPE_ALARM|RingtoneManager.TYPE_RINGTONE );
final Cursor ringtones = rm.getCursor();
List<String> mEntries = new ArrayList<String>();
List<String> mEntryValues = new ArrayList<String>();
for (ringtones.moveToFirst(); !ringtones.isAfterLast(); ringtones.moveToNext()) {
mEntries.add(ringtones.getString(RingtoneManager.TITLE_COLUMN_INDEX));
mEntryValues.add(ringtones.getString(RingtoneManager.URI_COLUMN_INDEX));
}
ringtonepref.setEntryValues(mEntryValues.toArray(new CharSequence[mEntryValues.size()]));
ringtonepref.setEntries(mEntries.toArray(new CharSequence[mEntries.size()]));
代码示例来源:origin: stackoverflow.com
...
RingtoneManager rm = new RingtoneManager( getActivity() );
rm.setType( RingtoneManager.TYPE_NOTIFICATION );
Cursor c = rm.getCursor();
while( c.moveToNext() )
{
String title = c.getString( RingtoneManager.TITLE_COLUMN_INDEX );
String id = c.getString( RingtoneManager.ID_COLUMN_INDEX );
String uri = c.getString( RingtoneManager.URI_COLUMN_INDEX );
// ...put it to a local list
}
c.close() // <<<< this line is the problem !!!
...
代码示例来源:origin: stackoverflow.com
String ringtoneTitle = "<The desired ringtone title>";
Uri parcialUri = Uri.parse("content://media/external/audio/media"); // also can be "content://media/internal/audio/media", depends on your needs
Uri finalSuccessfulUri;
RingtoneManager rm = new RingtoneManager(getApplicationContext());
Cursor cursor = rm.getCursor();
cursor.moveToFirst();
while(!cursor.isAfterLast()) {
if(ringtoneTitle.compareToIgnoreCase(cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.TITLE))) == 0) {
int ringtoneID = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
finalSuccessfulUri = Uri.withAppendedPath(parcialUri, "" + ringtoneID );
break;
}
cursor.moveToNext();
}
代码示例来源: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
public static Uri getNotificationSoundUri(Context context,String soundClipId)
{
RingtoneManager manager = new RingtoneManager(context);
manager.setType(RingtoneManager.TYPE_NOTIFICATION);
Cursor cursor = manager.getCursor();
ArrayList<NotificationSound> list = new ArrayList<>();
while (cursor.moveToNext()) {
if(soundClipId.equals(cursor.getString(RingtoneManager.ID_COLUMN_INDEX)))
{
return Uri.parse(cursor.getString(RingtoneManager.URI_COLUMN_INDEX)+"/"+cursor.getString(RingtoneManager.ID_COLUMN_INDEX));
}
}
return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
代码示例来源:origin: stackoverflow.com
public ArrayList<String> getNotificationSounds() {
RingtoneManager manager = new RingtoneManager(this);
manager.setType(RingtoneManager.TYPE_NOTIFICATION);
Cursor cursor = manager.getCursor();
ArrayList<String> list = new ArrayList<>();
while (cursor.moveToNext()) {
String id = cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
String uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);
list.add(uri + "/" + id);
}
return list;
}
代码示例来源:origin: stackoverflow.com
public Map<String, String> getNotifications() {
RingtoneManager manager = new RingtoneManager(this);
manager.setType(RingtoneManager.TYPE_NOTIFICATION);
Cursor cursor = manager.getCursor();
Map<String, String> list = new HashMap<>();
while (cursor.moveToNext()) {
String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
String notificationUri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);
list.put(notificationTitle, notificationUri);
}
return list;
}
代码示例来源:origin: stackoverflow.com
public Map<String, String> getNotifications() {
RingtoneManager manager = new RingtoneManager(this);
manager.setType(RingtoneManager.TYPE_RINGTONE);
Cursor cursor = manager.getCursor();
Map<String, String> list = new HashMap<>();
while (cursor.moveToNext()) {
String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
String notificationUri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);
list.put(notificationTitle, notificationUri);
}
return list;
}
代码示例来源:origin: stackoverflow.com
RingtoneManager rm = new RingtoneManager(getApplicationContext());
rm.setType(RingtoneManager.TYPE_ALARM);
Cursor c = rm.getCursor();
c.moveToFirst();
if (!c.isAfterLast()) {
do {
int uriString = c.getString(RingtoneManager.URI_COLUMN_INDEX);
Log.d("TC", uriString);
} while (c.moveToNext());
}
代码示例来源: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);
String uri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);
// Do something with the title and the URI of ringtone
}
}
代码示例来源:origin: werbhelius/MyCalendarDemo
public void getRing() {
/* 新建一个arraylist来接收从系统中获取的短信铃声数据 */
ringList = new ArrayList<String>();
/* 添加“跟随系统”选项 */
ringList.add("跟随系统");
/* 获取RingtoneManager */
rm = new RingtoneManager(context);
/* 指定获取类型为短信铃声 */
rm.setType(RingtoneManager.TYPE_RINGTONE);
/* 创建游标 */
cursor = rm.getCursor();
/* 游标移动到第一位,如果有下一项,则添加到ringlist中 */
if (cursor.moveToFirst()) {
do { // 游标获取RingtoneManager的列inde x
ringList.add(cursor
.getString(RingtoneManager.TITLE_COLUMN_INDEX));
} while (cursor.moveToNext());
}
}
代码示例来源: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
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
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
RingtoneManager ringtoneMgr = new RingtoneManager(this);
ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);
Cursor alCursor = ringtoneMgr.getCursor();
代码示例来源:origin: consp1racy/android-support-preference
@NonNull
@Override
public Cursor getCursor() {
try {
return super.getCursor();
} catch (SecurityException ex) {
if (!IS_AT_MOST_P) {
// We can do no workaround on Android P+.
throw ex;
}
Log.w(TAG, "No READ_EXTERNAL_STORAGE permission, ignoring ringtones on ext storage");
if (getIncludeDrm()) {
Log.w(TAG, "DRM ringtones are ignored.");
}
final Cursor cursor = getInternalRingtones();
setCursor(cursor);
return cursor;
}
}
}
代码示例来源: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: 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();
}
内容来源于网络,如有侵权,请联系作者删除!