Android select mp3 file

前端 未结 3 2176
故里飘歌
故里飘歌 2020-12-29 11:06

Sorry if this has already been answered, but I can\'t specify my question very well. I have an activity that needs a song file from your device, and I want it when I press a

3条回答
  •  我在风中等你
    2020-12-29 11:28

    Slight Correction to 2Dee's answer:

        Intent audiofile_chooser_intent;
        audiofile_chooser_intent = new Intent();
        audiofile_chooser_intent.setAction(Intent.ACTION_GET_CONTENT);
        audiofile_chooser_intent.setType("audio/*");
        ActivityOptions options = ActivityOptions.makeScaleUpAnimation(view, 0,
                0, view.getWidth(), view.getHeight());
        startActivityForResult(Intent.createChooser(audiofile_chooser_intent, getString(R.string.select_audio_file_title)), RQS_OPEN_AUDIO_MP3, options.toBundle());
    
        Toast("File Chooser initiated..");
    

    Intent inside of OnClick listener method to start FileChooser Activity/Dialog

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == RQS_OPEN_AUDIO_MP3) {
                Uri audioFileUri = data.getData();
    
                String MP3Path = audioFileUri.getPath();
                Toast(MP3Path);
    
    
            }
        }
    }
    

    OnActivityResult method for obtaining the FilePath of selected file for subsequent use

提交回复
热议问题