Andriod獲取系統自帶鈴聲 – Android移動開發技術文章_手機開發 Android移動開發教學課程

 

可以通過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); 

}   

發佈留言