在Android中以编程方式设置铃声

时间:2011-08-23 22:12:03

标签: android ringtone

大家好我想以编程方式设置设备铃声但应用程序崩溃。

我使用的代码是:

@Override
public void onClick(View v) {

    Uri uri = Uri.parse("android.resource://"
      +"com.ghzncl.barneystinsonsoundboard/"+R.raw.single]);

    RingtoneManager.setActualDefaultRingtoneUri(
      mContext, RingtoneManager.TYPE_NOTIFICATION, uri
    );

    // I set the data source of the mPlayer. I pass to 
    // the method the context and the uri of the resource.
    try{
        // I reset the mPlayer to its uninitialized state, in
        // this way I don't need to stop the previews running quotes. 
        mPlayer.reset();
        mPlayer.setDataSource(mContext,uri);
    }catch(Exception e){
        // Do Exception handling here...
    }

    try{
        mPlayer.prepare();
    }catch(Exception e){
        // Do Exception handling here...
    }

    //The quotes start
    mPlayer.start();
}

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

Nocola我使用此代码设置为铃声:

ContentValues values = new ContentValues(4);
long current = System.currentTimeMillis();
values.put(MediaStore.MediaColumns.DATA, path+audioname );
values.put(MediaStore.MediaColumns.TITLE,  path+audioname );
values.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/3gpp");
 //new
values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
values.put(MediaStore.Audio.Media.IS_ALARM, true);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);  
///new

但是我在这段代码中做了很多调整,不知怎的,我找到了tutorial关于如何以编程方式发出警报音,以及你自己的方式...... 只是做实验!

相关问题