HBiSoft / PickiT

An Android library that returns real paths from Uri's
MIT License
292 stars 54 forks source link

how can we pass Media store Id to get the file #42

Closed pawaom closed 2 years ago

pawaom commented 2 years ago

I am totally new to android 11 file access,

I have a simple question , I have an activity where we get the Song Id using MediaStore.Audio.Media._ID , I want to pass it to an activity which uses Jaudiotagger for which I need the file using File = new File(); which is in a separate activity.

So from activity A I pass the Intent extra like this

Long ExtraVal = SongId ; // MediaStore.Audio.Media._ID 
 Intent myIntent = new Intent(mcontext, ActivityToOpen);
        myIntent.putExtra("ExtraVal", ExtraVal);
        mcontext.startActivity(myIntent);

and in Activity B , I get it Like this,

Bundle extras = getIntent().getExtras();
        if (extras == null) {
            ExtraVal = null;
        } else {
            ExtraVal = extras.getLong("ExtraVal");
        }

How can I use this Id to get the file path and pass it to File = new File()

I am a total noob so please help

Also the startActivityForResult(intent, SELECT_VIDEO_REQUEST) is depreccated can you please update the example .

HBiSoft commented 2 years ago

Yes, startActivityForResult(intent, SELECT_VIDEO_REQUEST) is deprecated, but it's a demo application and it works as is. I will update it when I have the time.

As for your question, This library is meant to return a file path when querying the MediaStore, by passing the Uri and returning the file path.

It will not work when you pass the MediaStore.Audio.Media._ID. Instead, pass the Uri returned from MediaStore to PickiT and use the file path.

pawaom commented 2 years ago

can you please provide an example should I pass ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, songCursor.getLong(songCursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID))