Skip to content
Related Articles
Open in App
Not now

Related Articles

How to Fetch Audio file From Storage in Android?

Improve Article
Save Article
Like Article
  • Difficulty Level : Expert
  • Last Updated : 11 Jul, 2021
Improve Article
Save Article
Like Article

Selecting an audio file from the phone’s storage is required when the user is uploading or sending an audio file in your application. So this article primarily focuses on getting the audio files as a URI from your phone’s storage.

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Working with the activity_main.xml file

The XML layout of our app contains one Textview and if we click on it we can pick an audio file from our storage then as we pick it the text view’s text changes to audio pick. Use the following code to implement the XML layout. 


        android:text="Click to Select an Audio"
        tools:ignore="MissingConstraints" />

Step 3: Work with file

Here we trigger intent of type “Audio” and action as  ACTION_GET_CONTENT. Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Nullable;
public class MainActivity extends AppCompatActivity {
    private final int PICK_AUDIO = 1;
    Uri AudioUri;
    TextView select_Audio;
    protected void onCreate(Bundle savedInstanceState) {
        select_Audio = findViewById(;
        select_Audio.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent audio = new Intent();
                startActivityForResult(Intent.createChooser(audio, "Select Audio"), PICK_AUDIO);
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == PICK_AUDIO && resultCode == RESULT_OK) {
            // Audio is Picked in format of URI
            AudioUri = data.getData();
            select_Audio.setText("Audio Selected");

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!