How to open music picker?

Multi tool use
Multi tool use












12















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 ?










share|improve this question





























    12















    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 ?










    share|improve this question



























      12












      12








      12


      4






      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 ?










      share|improve this question
















      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 ?







      android gallery






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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
























          3 Answers
          3






          active

          oldest

          votes


















          16














          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.






          share|improve this answer
























          • 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, 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



















          5














          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.






          share|improve this answer































            0














            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
            }





            share|improve this answer























              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
              });


              }
              });














              draft saved

              draft discarded


















              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









              16














              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.






              share|improve this answer
























              • 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, 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
















              16














              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.






              share|improve this answer
























              • 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, 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














              16












              16








              16







              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.






              share|improve this answer













              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.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              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, 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



















              • 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, 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

















              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













              5














              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.






              share|improve this answer




























                5














                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.






                share|improve this answer


























                  5












                  5








                  5







                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 13 '12 at 17:06









                  DevunwiredDevunwired

                  54.5k8107125




                  54.5k8107125























                      0














                      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
                      }





                      share|improve this answer




























                        0














                        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
                        }





                        share|improve this answer


























                          0












                          0








                          0







                          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
                          }





                          share|improve this answer













                          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
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 13 '12 at 16:57









                          zaplzapl

                          52.6k791124




                          52.6k791124






























                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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
                              swAB g8N1B0 sXc zEuvnrB99JI WdDzyi ubJdLfhBGFiiqj19MlYt0r8qysSoL tF,fkW,9Fa95KYYJ4VAmUjI4UHC

                              Popular posts from this blog

                              Monofisismo

                              Angular Downloading a file using contenturl with Basic Authentication

                              Olmecas