Android onactivityresult returns null if picked using default picker

I had this strange problem, I've checked on SO and on the web found nothing and my code has no problems at all, I want to pick an audio file from a fragment here is my code:

public void onClick(View arg0)
{
    switch (arg0.getId())
    {
        case R.id.upload_btn_select_file:
            Intent musicIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            //musicIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
            startActivityForResult(musicIntent, REQ_MUSIC);
            break;
    }
}

and

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    Log.v("activity result" , "first enter");
    //handle music
    if( requestCode == REQ_MUSIC && resultCode == Activity.RESULT_OK  )
    {
        Log.v("activity result" , "ok");
        Log.v("data" , data.getData()+"");
    }
}

now if I pick a song with android default picker I get

03-10 17:55:40.160: V/activity result(32644): first enter
03-10 17:55:40.160: V/activity result(32644): ok
03-10 17:55:40.160: V/data(32644): null

but if I pick same song with es explorer picker I get

03-10 17:48:46.400: V/activity result(32644): first enter
03-10 17:48:46.400: V/activity result(32644): ok
03-10 17:48:46.400: V/data(32644): content://com.estrongs.files/mnt/sdcard/music/01%20-%20First%20Strike%20Is%20Deadly.mp3

I'm using android 4.0 on xperia-neo-v, is there anything I can do in code to fix this? or it's just sony's build?

Answers


I've added a check to the received intent and found it has keys

Iterator<String> keyset= data.getExtras().keySet().iterator();
while( keyset.hasNext())
    Log.v("key" , keyset.next());

then grabbed that extra which contains the uri

Log.v("uri" , data.getExtras().get(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)+"");

Most likely the default picker is not returning the result inside the getData. (You cannot assume that all pickers will return data in the same way)

Perhaps it is returning the result inside an extra within the data object instead.

check out the extras. i.e data.getExtras()


There are no guarantees that you are really getting data from the intents you are executing from your app.

I have tried to get results from several apps (Facebook, Twitter, Instagram) and the result was everytime: Nothing.

I think this isn't even the default android Ringtone picker, Sony replaces AFAIR the android default thing with a customized intent.


Need Your Help

StyleCop equivalent for SQL Server?

sql-server coding-style stylecop

Is there any tools like StyleCop for SQL Server?