本文整理了Java中android.media.RingtoneManager.setType
方法的一些代码示例,展示了RingtoneManager.setType
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RingtoneManager.setType
方法的具体详情如下:
包路径:android.media.RingtoneManager
类名称:RingtoneManager
方法名:setType
暂无
代码示例来源: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
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
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 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: 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: 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: 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();
}
代码示例来源:origin: fennifith/Alarmio
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_sound_chooser_list, container, false);
RecyclerView recyclerView = view.findViewById(R.id.recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
List<SoundData> sounds = new ArrayList<>();
RingtoneManager manager = new RingtoneManager(getContext());
manager.setType(RingtoneManager.TYPE_ALARM);
Cursor cursor = manager.getCursor();
int count = cursor.getCount();
if (count > 0 && cursor.moveToFirst()) {
do {
sounds.add(new SoundData(cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX), cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/" + cursor.getString(RingtoneManager.ID_COLUMN_INDEX)));
} while (cursor.moveToNext());
}
SoundsAdapter adapter = new SoundsAdapter(getAlarmio(), sounds);
adapter.setListener(this);
recyclerView.setAdapter(adapter);
return view;
}
代码示例来源: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: 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();
}
}
内容来源于网络,如有侵权,请联系作者删除!