title: Android Getting pdf file's path from my app
body: <p>I am doing an android application. The objective is given below.</p>
  
  <blockquote>
    <p><strong>Objective:</strong></p>
  </blockquote>
  
  <p>If the user want to share the pdf (or) image file form anywhere in their android mobile device, they will have the option of my app in the share list. I want to know, whether the user selected the pdf file or an image. For that I used the following code.</p>
  
  <blockquote>
    <p>In <strong>AndroidManifest.xml</strong></p>
  </blockquote>
  
  <pre><code>&lt;activity
      android:name="com.share.FileActivity"
      android:screenOrientation="portrait"
      android:theme="@android:style/Theme.NoTitleBar" &gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.intent.action.SEND" /&gt;
          &lt;data android:mimeType="application/pdf" /&gt;                
          &lt;data android:mimeType="image/*" /&gt;
          &lt;category android:name="android.intent.category.DEFAULT" /&gt;
      &lt;/intent-filter&gt;
  &lt;/activity&gt;
  </code></pre>
  
  <blockquote>
    <p>In <strong>FileActivity.java</strong>, to get the selected file URI</p>
  </blockquote>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      Intent myintent = getIntent();
      Bundle extras = myintent.getExtras();
      String action = myintent.getAction();
      if (Intent.ACTION_SEND.equals(action)) {
          if (extras.containsKey(Intent.EXTRA_STREAM)) {
              URI uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
              .
              .
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p><strong>Issue:</strong></p>
  </blockquote>
  
  <p>If I open pdf from the file explorer I am getting the correct URI as "<strong>file:///storage/emulated/0/Download/test.pdf</strong>". so that I can identify as pdf or image. </p>
  
  <p>But If I open the pdf file from the google drive app, I am getting the following URI "<strong>content://com.google.android.apps.docs.storage.legacy/enc%3Du4Ss-AYnclkKv-lfNmA3wY7YBbb_JxRfayDTvfQfHWokHkoy%0A</strong>". So I couldn't identify the selected file. </p>
  
  <p>How can I get the file type from the above URI. Help me to fix this issue?</p>