0

I'm trying to write a function which simply shows all of the music files (mp3) available in users phone (internal/external memory) and return the selected file with a callback "interface".

Here is what I have but I don't have the callback! * I use API 16 (JB 4.1) *

    public void pickMusic() {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
        intent.setType("audio/*");
        try {
            getContext().startActivity(intent);
        }
        catch (Throwable e) {
            Log.d(TAG, "pickMusic: " + e.getLocalizedMessage());
            e.printStackTrace();
        }
    }

If you know a better way of doing this please share. Thanks in advance.

Edit: I use a different API level! "startActivityForResult" don't show up for me, my application is a subclass of Application class.

Mac A.
  • 103
  • 8
  • Possible duplicate of [URI from Intent.ACTION\_GET\_CONTENT into File](http://stackoverflow.com/questions/8646246/uri-from-intent-action-get-content-into-file) – Ken Y-N May 09 '17 at 01:25
  • You need to override the activity's `onActivityResult` function, that is the callback. You can find more details about that [HERE](https://developer.android.com/training/basics/intents/result.html). – Titus May 09 '17 at 01:25
  • Re your edit: [see this question](http://stackoverflow.com/q/21780252/1270789). – Ken Y-N May 09 '17 at 01:55
  • Oh ok I got it now, it had to be an override within my activity class! thank you! – Mac A. May 09 '17 at 02:01

0 Answers0