当前位置:操作系统 > 安卓/Android >>

Andriod获取系统自带铃声

 

可以通过RingtoneManager 设置type 后,获取到Ringtone对象。或则其Uri。

Ringtone可以直接进行播放操作。

Java代码 

public Ringtone getDefaultRingtone(int type){ 

    return RingtoneManager.getRingtone(mContext, RingtoneManager.getActualDefaultRingtoneUri(mContext, type)); 

 

public Uri getDefaultRingtoneUri(int type){ 

    return RingtoneManager.getActualDefaultRingtoneUri(mContext, type); 

 

public List<Ringtone> getRingtoneList(int type){ 

    List<Ringtone> resArr = new ArrayList<Ringtone>(); 

    RingtoneManager manager = new RingtoneManager(mContext); 

    manager.setType(type); 

    Cursor cursor = manager.getCursor(); 

    int count = cursor.getCount(); 

    for(int i = 0 ; i < count ; i ++){ 

        resArr.add(manager.getRingtone(i)); 

    } 

    return resArr; 

 

public Ringtone getRingtone(int type,int pos){ 

    RingtoneManager manager = new RingtoneManager(mContext); 

    manager.setType(type); 

    return manager.getRingtone(pos); 

 

public List<String> getRingtoneTitleList(int type){ 

    List<String> resArr = new ArrayList<String>(); 

    RingtoneManager manager = new RingtoneManager(mContext); 

    manager.setType(type); 

    Cursor cursor = manager.getCursor(); 

    if(cursor.moveToFirst()){ 

        do{ 

            resArr.add(cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX)); 

        }while(cursor.moveToNext()); 

    } 

    return resArr; 

}  

 

 

public String getRingtoneUriPath(int type,int pos,String def){ 

    RingtoneManager manager = new RingtoneManager(mContext); 

    manager.setType(type); 

    Uri uri = manager.getRingtoneUri(pos); 

    return uri==null?def:uri.toString(); 

 

public Ringtone getRingtoneByUriPath(int type ,String uriPath){ 

    RingtoneManager manager = new RingtoneManager(mContext); 

    manager.setType(type); 

    Uri uri = Uri.parse(uriPath); 

    return manager.getRingtone(mContext, uri); 

}   

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,