2

こんにちは、デバイスの着信音をプログラムで設定したいのですが、アプリケーションがクラッシュします。

私が使用したコードは次のとおりです。

@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();
}

誰でも私を助けてもらえますか??

4

1 に答える 1

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

しかし、私はこのコードで多くの微調整を行いました。どういうわけか、プログラムでアラーム音を作成する方法に関するチュートリアルと、独自の方法を見つけました...実験をしてください!

于 2015-06-17T02:03:24.277 に答える