铃声选择器始终返回null intent

时间:2015-01-02 09:32:51

标签: android android-intent

我正在尝试从铃声选择器中读取值,但在onactivityresult中我得到NULL意图。

以下是我用来启动铃声选择器的代码

    Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select ringtone for notifications:");
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_NOTIFICATION);
    startActivityForResult(intent,999);

这里我在onactivityresult中得到NULL作为响应,响应代码requestCode为100. resultcode 0

requestCode应为999,但我得到100。

@Override  
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        //Data i get as NULL, it should be valid intent 
       super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {

        case 100:

Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

         }
} 

1 个答案:

答案 0 :(得分:2)

我知道这真的很晚了,但这就是它需要做的事情

Uri pickedUri= (Uri) data.getExtras().get(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);