title: android - how to play a mp3 file from file manager in my music player?
body: <p>I have created a music player app in android studio. When I run it, there is no issue and the app is running well but when I try to play a song from file manager, the app selection popup shows my app. When I select my music player, it opens music player but not playing the song. only shows the last played song. How can I automatically play the selected song? Is there any intent I need to capture?</p>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;activity
          android:name=".activities.MainActivity"
          android:label="@string/app_name"
          android:screenOrientation="portrait"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;action android:name="android.intent.action.VIEW" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;data android:scheme="content"/&gt;
              &lt;data android:scheme="file"/&gt;
              &lt;data android:mimeType="audio/*"/&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
  
      sMainActivity = this;
      action = getIntent().getAction();
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      navigationMap.put(Constants.NAVIGATE_LIBRARY, navigateLibrary);
      navigationMap.put(Constants.NAVIGATE_PLAYLIST, navigatePlaylist);
      navigationMap.put(Constants.NAVIGATE_QUEUE, navigateQueue);
      navigationMap.put(Constants.NAVIGATE_NOWPLAYING, navigateNowplaying);
      navigationMap.put(Constants.NAVIGATE_ALBUM, navigateAlbum);
      navigationMap.put(Constants.NAVIGATE_ARTIST, navigateArtist);
  
      mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
      panelLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
  
      navigationView = (NavigationView) findViewById(R.id.nav_view);
      View header = navigationView.inflateHeaderView(R.layout.nav_header);
  
      albumart = (ImageView) header.findViewById(R.id.album_art);
      songtitle = (TextView) header.findViewById(R.id.song_title);
      songartist = (TextView) header.findViewById(R.id.song_artist);
  
      setPanelSlideListeners(panelLayout);
  
      navDrawerRunnable.postDelayed(new Runnable() {
          @Override
          public void run() {
              setupDrawerContent(navigationView);
              setupNavigationIcons(navigationView);
          }
      }, 700);
  
  
      if (RamUtils.isMarshmallow()) {
          checkPermissionAndThenLoad();
      } else {
          loadEverything();
      }
  
      addBackstackListener();
  }
  </code></pre>