将媒体文件设置为铃声时出现问题

时间:2011-07-26 20:43:07

标签: android

我试图在长时间点击时将资源中的音频文件设置为用户的铃声。我无法做到这一点 - 我没有得到FC,但是当我接到电话时,它是一个无声的铃声。我进入设置并选择设置铃声,我可以看到我创建的文件的名称,但它不起作用。

这是我的java代码:

String filepath = "/sdcard/fightsong.mp3";
File ringtoneFile = new File(filepath);

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.long_click_test);

    ContentValues content = new ContentValues();
    content.put(MediaStore.MediaColumns.DATA, ringtoneFile.getAbsolutePath());
    content.put(MediaStore.MediaColumns.TITLE, "Fight Song");
    content.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
    content.put(MediaStore.Audio.Media.IS_RINGTONE, true);


    Log.i(TAG, "the absolute path of the file is :"+ringtoneFile.getAbsolutePath()); 
    Uri uri = MediaStore.Audio.Media.getContentUriForPath(ringtoneFile.getAbsolutePath()); 
    Uri newUri = this.getContentResolver().insert(uri, content); 
    Uri ringtoneUri = newUri; 
    Log.i(TAG,"the ringtone uri is :"+ringtoneUri); 
    RingtoneManager.setActualDefaultRingtoneUri(this,RingtoneManager.TYPE_RINGTONE,newUri); 

这是onLongClick的代码,以及将其传递给上面代码的位:

private OnLongClickListener onLongImageClick = new OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
            case R.id.boston_college_imageview:
                SetRingtone(R.raw.acc_boston_college);
            break;
        }
        return true;
    }
};

private void SetRingtone(int soundID) {
    Intent myIntent = new Intent();
    myIntent.setClassName("com.carboni.fightsongs", "com.carboni.fightsongs.SetRingtone");
    myIntent.putExtra("com.carboni.fightsongs.FILE_RES_ID", soundID);
    startActivity(myIntent);
}

我在Manifest中设置了权限和Java。

这是我的Logcat错误:

 07-26 16:32:38.152: ERROR/Database(309): Error inserting album_id=8 title=Fight Song title_key=Q7Q=Q9Q;QSQQQQIQGQ9Q mime_type=audio/mp3 date_added=1311712358 _display_name=fightsong.mp3 is_ringtone=true artist_id=1 _data=/sdcard/fightsong.mp3
07-26 16:32:38.152: ERROR/Database(309): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
07-26 16:32:38.152: ERROR/Database(309):     at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
07-26 16:32:38.152: ERROR/Database(309):     at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:61)
07-26 16:32:38.152: ERROR/Database(309):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1582)
07-26 16:32:38.152: ERROR/Database(309):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1426)
07-26 16:32:38.152: ERROR/Database(309):     at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:1940)
07-26 16:32:38.152: ERROR/Database(309):     at com.android.providers.media.MediaProvider.insert(MediaProvider.java:1759)
07-26 16:32:38.152: ERROR/Database(309):     at android.content.ContentProvider$Transport.insert(ContentProvider.java:198)
07-26 16:32:38.152: ERROR/Database(309):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:146)
07-26 16:32:38.152: ERROR/Database(309):     at android.os.Binder.execTransact(Binder.java:320)
07-26 16:32:38.152: ERROR/Database(309):     at dalvik.system.NativeStart.run(Native Method)
07-26 16:32:38.156: INFO/CFFS(32664): the ringtone uri is :null

0 个答案:

没有答案