title: How to open a single image in my app from file explorer
body: <p>I am working on an app in which I want to open any photo in my app from external file explorer. Like when I click on photo, choose applications window appears and I select my app and image is shown in my app. But here, no image appears.</p>
  
  <p><strong>I added code in <code>Manifest.xml</code>:</strong></p>
  
  <pre><code>&lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.image.MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.SEND" /&gt;
                  &lt;action android:name="android.intent.action.VIEW" /&gt;
                  &lt;action android:name="android.intent.action.EDIT" /&gt;
  
                  &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
  
                  &lt;data android:mimeType="image/*" /&gt;
                  &lt;data android:mimeType="text/*" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p><strong>Layout file <code>activity_main.xml</code></strong> </p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:padding="10dp"
      tools:context=".DataReceiverActivity" &gt;
  
      &lt;ImageView
          android:id="@+id/picture"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:contentDescription="Receive Picture Sharing" /&gt;
  
      &lt;TextView
          android:id="@+id/txt"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>And in my <code>MainActivity.java</code>:</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          ImageView picView = (ImageView) findViewById(R.id.picture);
          TextView txtView = (TextView) findViewById(R.id.txt);
  
          Intent receivedIntent = getIntent();
          String receivedAction = receivedIntent.getAction();
          String receivedType = receivedIntent.getType();
  
          // make sure it's an action and type we can handle
          if (receivedAction.equals(Intent.ACTION_SEND)) {
              if (receivedType.startsWith("text/")) {
                  picView.setVisibility(View.GONE);
                  String receivedText = receivedIntent
                      .getStringExtra(Intent.EXTRA_TEXT);
                  if (receivedText != null) {
                      txtView.setText(receivedText);
                  }
              } else if (receivedType.startsWith("image/")) {
                  txtView.setVisibility(View.GONE);
                  Uri receivedUri = (Uri) receivedIntent
                      .getParcelableExtra(Intent.EXTRA_STREAM);
                  if (receivedUri != null) {
                      picView.setImageURI(receivedUri);// just for demonstration
                  }
              }
          } else if (receivedAction.equals(Intent.ACTION_VIEW)) {
  
              if (receivedType.startsWith("text/")) {
                  Toast.makeText(this, "TextRecived", Toast.LENGTH_SHORT).show();
                  Uri uri2 = receivedIntent.getData();
                  String uri = uri2.getEncodedPath() + "  complete: "
                      + uri2.toString();
                  txtView.setText(uri);
              } else if (receivedType.startsWith("image/")) {
  
                  txtView.setVisibility(View.GONE);
                  Uri receivedUri = (Uri) receivedIntent
                      .getParcelableExtra(Intent.EXTRA_STREAM);
                  Toast.makeText(this, receivedUri.toString(), Toast.LENGTH_SHORT).show();
                  if (receivedUri != null) {
                      picView.setImageURI(receivedUri);// just for demonstration
                  }
              }
          } else if (receivedAction.equals(Intent.ACTION_MAIN)) {
              txtView.setText("-----------------------------");
          }
      }
  
  }
  </code></pre>
  
  <p><strong>Here are my screenshots:</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/mM6Vv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mM6Vv.png" alt="opening image from explorer"></a>
  <a href="https://i.stack.imgur.com/mxYL0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mxYL0.png" alt="when selecting my app empty screen appare"></a></p>