android RingtoneManger 问题讨论

RingtoneManger 在部分机型上设置了通知铃声无效, 例如lenovo 4.2.2 ,但是在三星的4.2.2上面设置就成功,个人有点感觉跟uri有关,但是uri都有值,想问问有大神懂这问题吗?
测试代码如下
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private File[] files ;
private int i = 0 ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
File sdDir = null ;
if( Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){
sdDir = new File(Environment.getExternalStorageDirectory().getPath()+"/Audio/Soundrecorder");
files = sdDir.listFiles();
}
findViewById(R.id.alterRing).setOnClickListener(this);
}

//设置为短信铃声
static void setMyMessage(Context context, String path) {
    Log.d("tag","absoultpath:"+path);
    File sdfile = new File(path);
    ContentValues values = new ContentValues();
    values.put(MediaStore.MediaColumns.DATA, sdfile.getAbsolutePath());
    values.put(MediaStore.MediaColumns.TITLE, sdfile.getName());
    values.put(MediaStore.MediaColumns.SIZE, sdfile.length());
    values.put(MediaStore.Audio.Media.IS_RINGTONE, false);
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
    values.put(MediaStore.Audio.Media.IS_ALARM, false);
    values.put(MediaStore.Audio.Media.IS_MUSIC, false);

    Uri uri = MediaStore.Audio.Media.getContentUriForPath(path);
    ContentResolver cr =context.getContentResolver();
    Cursor cursor = cr.query(uri,new String[]{MediaStore.MediaColumns._ID},"_data = ? ",new String[]{path},null,null);
    cursor.moveToFirst();
    int ringtoneID = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
    Uri newUri = ContentUris.withAppendedId(uri, Long.valueOf(ringtoneID));
    RingtoneManager.setActualDefaultRingtoneUri(context,RingtoneManager.TYPE_NOTIFICATION,newUri);
    Intent i = new Intent("com.android.mms.change.ring");
    i.putExtra("newUri", uri.toString());
    context.sendBroadcast(i);//发一个广播到短信模块,让短信模块自己修改自己的SharedPreferences

    Toast.makeText(context, "setMessage-----"+sdfile.getName()+"---------------->",
            Toast.LENGTH_SHORT).show();
}

@Override
public void onClick(View view) {
    switch (view.getId()){
        case R.id.alterRing :
            setMyMessage(MainActivity.this,files[i].getAbsolutePath()) ;
            i++;
            break;
    }
}

}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问