How to open music picker?

Multi tool use
In my application, I want to make a picker that offers the user the choice to pick a music. I want to use the native android picker. I used the following code to open the native android music picker:
final Intent intent2 = new Intent(Intent.ACTION_PICK);
intent2.setType("audio/*");
startActivityForResult(intent2, 1);
But when I execute it, I get an ActivityNotFoundException and this error message:
"Your phone has no music gallery that can be used to select a file. Please try sending a different type of files"
Am I doing something wrong there ?

add a comment |
In my application, I want to make a picker that offers the user the choice to pick a music. I want to use the native android picker. I used the following code to open the native android music picker:
final Intent intent2 = new Intent(Intent.ACTION_PICK);
intent2.setType("audio/*");
startActivityForResult(intent2, 1);
But when I execute it, I get an ActivityNotFoundException and this error message:
"Your phone has no music gallery that can be used to select a file. Please try sending a different type of files"
Am I doing something wrong there ?

add a comment |
In my application, I want to make a picker that offers the user the choice to pick a music. I want to use the native android picker. I used the following code to open the native android music picker:
final Intent intent2 = new Intent(Intent.ACTION_PICK);
intent2.setType("audio/*");
startActivityForResult(intent2, 1);
But when I execute it, I get an ActivityNotFoundException and this error message:
"Your phone has no music gallery that can be used to select a file. Please try sending a different type of files"
Am I doing something wrong there ?

In my application, I want to make a picker that offers the user the choice to pick a music. I want to use the native android picker. I used the following code to open the native android music picker:
final Intent intent2 = new Intent(Intent.ACTION_PICK);
intent2.setType("audio/*");
startActivityForResult(intent2, 1);
But when I execute it, I get an ActivityNotFoundException and this error message:
"Your phone has no music gallery that can be used to select a file. Please try sending a different type of files"
Am I doing something wrong there ?


edited Dec 30 '18 at 20:29
Matthieu Brucher
15.3k32140
15.3k32140
asked Aug 13 '12 at 16:40
Jean-Simon VaillantJean-Simon Vaillant
1291314
1291314
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
This worked well for me:
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,1);
The more general intent with Intent.ACTION_GET_CONTENT can present the user with a number of options for activities to pick an audio file (Astro file manager, etc.). However, the user could select any file, not necessarily an audio file. I wanted one that simply allowed the user to select an audio file from their media. This did the trick.
Excellent, please give example for the file storing
– Alaa Eldin
Jun 27 '13 at 18:44
see complete example here: sudhanshuvinodgupta.blogspot.co.il/2012/07/…
– Guy
Apr 8 '14 at 8:41
Intent.ACTION_GET_CONTENT
is indeed a nice picker... it even lets me open a file on my OneDrive. In Comparison, theACTION_PICK
ofMedia.EXTERNAL_CONTENT_URI
is more concise... question: with ACTION_PICK method, how is it possible to pre-select the currently selected item ? (It shows the picker with nothing already selected)
– Someone Somewhere
Dec 17 '15 at 14:21
@Craig This doesn't show downloaded music in some devices
– salman
Aug 13 '18 at 6:05
add a comment |
If you take a look at the AndroidManifest.xml file for the latest core Music app, it may shed some light on the options that you have. For example:
<activity android:name="com.android.music.MusicPicker"
android:label="@string/music_picker_title" android:exported="true" >
<!-- First way to invoke us: someone asks to get content of
any of the audio types we support. -->
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="audio/*"/>
<data android:mimeType="application/ogg"/>
<data android:mimeType="application/x-ogg"/>
</intent-filter>
<!-- Second way to invoke us: someone asks to pick an item from
some media Uri. -->
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="vnd.android.cursor.dir/audio"/>
</intent-filter>
</activity>
So based on this, you might first try
final Intent intent2 = new Intent(Intent.ACTION_GET_CONTENT);
intent2.setType("audio/*");
startActivityForResult(intent2, 1);
and see if it fits your needs. You may also look at adding the category flags noted in the above example to help narrow down the results (e.g. OPENABLE
should filter to only content that can be opened as a stream.
add a comment |
Something along the lines of this may work
// some Intent that points to whatever you like to play
Intent play = new Intent(Intent.ACTION_VIEW);
play.setData(Uri.fromFile(new File("/path/to/file")));
// create chooser for that intent
try {
Intent i = Intent.createChooser(play, "Play Music");
c.startActivity(i);
} catch(ActivityNotFoundException ex) {
// if no app handles it, do nothing
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11938579%2fhow-to-open-music-picker%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
This worked well for me:
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,1);
The more general intent with Intent.ACTION_GET_CONTENT can present the user with a number of options for activities to pick an audio file (Astro file manager, etc.). However, the user could select any file, not necessarily an audio file. I wanted one that simply allowed the user to select an audio file from their media. This did the trick.
Excellent, please give example for the file storing
– Alaa Eldin
Jun 27 '13 at 18:44
see complete example here: sudhanshuvinodgupta.blogspot.co.il/2012/07/…
– Guy
Apr 8 '14 at 8:41
Intent.ACTION_GET_CONTENT
is indeed a nice picker... it even lets me open a file on my OneDrive. In Comparison, theACTION_PICK
ofMedia.EXTERNAL_CONTENT_URI
is more concise... question: with ACTION_PICK method, how is it possible to pre-select the currently selected item ? (It shows the picker with nothing already selected)
– Someone Somewhere
Dec 17 '15 at 14:21
@Craig This doesn't show downloaded music in some devices
– salman
Aug 13 '18 at 6:05
add a comment |
This worked well for me:
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,1);
The more general intent with Intent.ACTION_GET_CONTENT can present the user with a number of options for activities to pick an audio file (Astro file manager, etc.). However, the user could select any file, not necessarily an audio file. I wanted one that simply allowed the user to select an audio file from their media. This did the trick.
Excellent, please give example for the file storing
– Alaa Eldin
Jun 27 '13 at 18:44
see complete example here: sudhanshuvinodgupta.blogspot.co.il/2012/07/…
– Guy
Apr 8 '14 at 8:41
Intent.ACTION_GET_CONTENT
is indeed a nice picker... it even lets me open a file on my OneDrive. In Comparison, theACTION_PICK
ofMedia.EXTERNAL_CONTENT_URI
is more concise... question: with ACTION_PICK method, how is it possible to pre-select the currently selected item ? (It shows the picker with nothing already selected)
– Someone Somewhere
Dec 17 '15 at 14:21
@Craig This doesn't show downloaded music in some devices
– salman
Aug 13 '18 at 6:05
add a comment |
This worked well for me:
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,1);
The more general intent with Intent.ACTION_GET_CONTENT can present the user with a number of options for activities to pick an audio file (Astro file manager, etc.). However, the user could select any file, not necessarily an audio file. I wanted one that simply allowed the user to select an audio file from their media. This did the trick.
This worked well for me:
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,1);
The more general intent with Intent.ACTION_GET_CONTENT can present the user with a number of options for activities to pick an audio file (Astro file manager, etc.). However, the user could select any file, not necessarily an audio file. I wanted one that simply allowed the user to select an audio file from their media. This did the trick.
answered Jun 22 '13 at 15:56
Craig BCraig B
4,09912018
4,09912018
Excellent, please give example for the file storing
– Alaa Eldin
Jun 27 '13 at 18:44
see complete example here: sudhanshuvinodgupta.blogspot.co.il/2012/07/…
– Guy
Apr 8 '14 at 8:41
Intent.ACTION_GET_CONTENT
is indeed a nice picker... it even lets me open a file on my OneDrive. In Comparison, theACTION_PICK
ofMedia.EXTERNAL_CONTENT_URI
is more concise... question: with ACTION_PICK method, how is it possible to pre-select the currently selected item ? (It shows the picker with nothing already selected)
– Someone Somewhere
Dec 17 '15 at 14:21
@Craig This doesn't show downloaded music in some devices
– salman
Aug 13 '18 at 6:05
add a comment |
Excellent, please give example for the file storing
– Alaa Eldin
Jun 27 '13 at 18:44
see complete example here: sudhanshuvinodgupta.blogspot.co.il/2012/07/…
– Guy
Apr 8 '14 at 8:41
Intent.ACTION_GET_CONTENT
is indeed a nice picker... it even lets me open a file on my OneDrive. In Comparison, theACTION_PICK
ofMedia.EXTERNAL_CONTENT_URI
is more concise... question: with ACTION_PICK method, how is it possible to pre-select the currently selected item ? (It shows the picker with nothing already selected)
– Someone Somewhere
Dec 17 '15 at 14:21
@Craig This doesn't show downloaded music in some devices
– salman
Aug 13 '18 at 6:05
Excellent, please give example for the file storing
– Alaa Eldin
Jun 27 '13 at 18:44
Excellent, please give example for the file storing
– Alaa Eldin
Jun 27 '13 at 18:44
see complete example here: sudhanshuvinodgupta.blogspot.co.il/2012/07/…
– Guy
Apr 8 '14 at 8:41
see complete example here: sudhanshuvinodgupta.blogspot.co.il/2012/07/…
– Guy
Apr 8 '14 at 8:41
Intent.ACTION_GET_CONTENT
is indeed a nice picker... it even lets me open a file on my OneDrive. In Comparison, the ACTION_PICK
of Media.EXTERNAL_CONTENT_URI
is more concise... question: with ACTION_PICK method, how is it possible to pre-select the currently selected item ? (It shows the picker with nothing already selected)– Someone Somewhere
Dec 17 '15 at 14:21
Intent.ACTION_GET_CONTENT
is indeed a nice picker... it even lets me open a file on my OneDrive. In Comparison, the ACTION_PICK
of Media.EXTERNAL_CONTENT_URI
is more concise... question: with ACTION_PICK method, how is it possible to pre-select the currently selected item ? (It shows the picker with nothing already selected)– Someone Somewhere
Dec 17 '15 at 14:21
@Craig This doesn't show downloaded music in some devices
– salman
Aug 13 '18 at 6:05
@Craig This doesn't show downloaded music in some devices
– salman
Aug 13 '18 at 6:05
add a comment |
If you take a look at the AndroidManifest.xml file for the latest core Music app, it may shed some light on the options that you have. For example:
<activity android:name="com.android.music.MusicPicker"
android:label="@string/music_picker_title" android:exported="true" >
<!-- First way to invoke us: someone asks to get content of
any of the audio types we support. -->
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="audio/*"/>
<data android:mimeType="application/ogg"/>
<data android:mimeType="application/x-ogg"/>
</intent-filter>
<!-- Second way to invoke us: someone asks to pick an item from
some media Uri. -->
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="vnd.android.cursor.dir/audio"/>
</intent-filter>
</activity>
So based on this, you might first try
final Intent intent2 = new Intent(Intent.ACTION_GET_CONTENT);
intent2.setType("audio/*");
startActivityForResult(intent2, 1);
and see if it fits your needs. You may also look at adding the category flags noted in the above example to help narrow down the results (e.g. OPENABLE
should filter to only content that can be opened as a stream.
add a comment |
If you take a look at the AndroidManifest.xml file for the latest core Music app, it may shed some light on the options that you have. For example:
<activity android:name="com.android.music.MusicPicker"
android:label="@string/music_picker_title" android:exported="true" >
<!-- First way to invoke us: someone asks to get content of
any of the audio types we support. -->
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="audio/*"/>
<data android:mimeType="application/ogg"/>
<data android:mimeType="application/x-ogg"/>
</intent-filter>
<!-- Second way to invoke us: someone asks to pick an item from
some media Uri. -->
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="vnd.android.cursor.dir/audio"/>
</intent-filter>
</activity>
So based on this, you might first try
final Intent intent2 = new Intent(Intent.ACTION_GET_CONTENT);
intent2.setType("audio/*");
startActivityForResult(intent2, 1);
and see if it fits your needs. You may also look at adding the category flags noted in the above example to help narrow down the results (e.g. OPENABLE
should filter to only content that can be opened as a stream.
add a comment |
If you take a look at the AndroidManifest.xml file for the latest core Music app, it may shed some light on the options that you have. For example:
<activity android:name="com.android.music.MusicPicker"
android:label="@string/music_picker_title" android:exported="true" >
<!-- First way to invoke us: someone asks to get content of
any of the audio types we support. -->
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="audio/*"/>
<data android:mimeType="application/ogg"/>
<data android:mimeType="application/x-ogg"/>
</intent-filter>
<!-- Second way to invoke us: someone asks to pick an item from
some media Uri. -->
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="vnd.android.cursor.dir/audio"/>
</intent-filter>
</activity>
So based on this, you might first try
final Intent intent2 = new Intent(Intent.ACTION_GET_CONTENT);
intent2.setType("audio/*");
startActivityForResult(intent2, 1);
and see if it fits your needs. You may also look at adding the category flags noted in the above example to help narrow down the results (e.g. OPENABLE
should filter to only content that can be opened as a stream.
If you take a look at the AndroidManifest.xml file for the latest core Music app, it may shed some light on the options that you have. For example:
<activity android:name="com.android.music.MusicPicker"
android:label="@string/music_picker_title" android:exported="true" >
<!-- First way to invoke us: someone asks to get content of
any of the audio types we support. -->
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="audio/*"/>
<data android:mimeType="application/ogg"/>
<data android:mimeType="application/x-ogg"/>
</intent-filter>
<!-- Second way to invoke us: someone asks to pick an item from
some media Uri. -->
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="vnd.android.cursor.dir/audio"/>
</intent-filter>
</activity>
So based on this, you might first try
final Intent intent2 = new Intent(Intent.ACTION_GET_CONTENT);
intent2.setType("audio/*");
startActivityForResult(intent2, 1);
and see if it fits your needs. You may also look at adding the category flags noted in the above example to help narrow down the results (e.g. OPENABLE
should filter to only content that can be opened as a stream.
answered Aug 13 '12 at 17:06


DevunwiredDevunwired
54.5k8107125
54.5k8107125
add a comment |
add a comment |
Something along the lines of this may work
// some Intent that points to whatever you like to play
Intent play = new Intent(Intent.ACTION_VIEW);
play.setData(Uri.fromFile(new File("/path/to/file")));
// create chooser for that intent
try {
Intent i = Intent.createChooser(play, "Play Music");
c.startActivity(i);
} catch(ActivityNotFoundException ex) {
// if no app handles it, do nothing
}
add a comment |
Something along the lines of this may work
// some Intent that points to whatever you like to play
Intent play = new Intent(Intent.ACTION_VIEW);
play.setData(Uri.fromFile(new File("/path/to/file")));
// create chooser for that intent
try {
Intent i = Intent.createChooser(play, "Play Music");
c.startActivity(i);
} catch(ActivityNotFoundException ex) {
// if no app handles it, do nothing
}
add a comment |
Something along the lines of this may work
// some Intent that points to whatever you like to play
Intent play = new Intent(Intent.ACTION_VIEW);
play.setData(Uri.fromFile(new File("/path/to/file")));
// create chooser for that intent
try {
Intent i = Intent.createChooser(play, "Play Music");
c.startActivity(i);
} catch(ActivityNotFoundException ex) {
// if no app handles it, do nothing
}
Something along the lines of this may work
// some Intent that points to whatever you like to play
Intent play = new Intent(Intent.ACTION_VIEW);
play.setData(Uri.fromFile(new File("/path/to/file")));
// create chooser for that intent
try {
Intent i = Intent.createChooser(play, "Play Music");
c.startActivity(i);
} catch(ActivityNotFoundException ex) {
// if no app handles it, do nothing
}
answered Aug 13 '12 at 16:57
zaplzapl
52.6k791124
52.6k791124
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11938579%2fhow-to-open-music-picker%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
uXh08wRPP6wCUkqsHwov7lEW0ji3IX 1lAd1rjr94QA8rTYGQMyIGPX K,Zlvl6k,hkxGtFiuJwdgXG3 OW8PLJ