title: save image in gallary and get file path android
body: <p>I am new to Android. I want to save an <code>image</code> in gallery from <code>URL</code> and get file name and path of saved image. So i can open it with <code>onclick</code> in gallery.
  I tried many solution but I couldn't find proper way to get saved <code>file path</code>.</p>
  
  <p>All i want to do is open an image in gallery form <code>URL</code> on <code>onclick</code>.</p>
  
  <p>my code </p>
  
  <pre><code>   activity_edit_profile_basic_imageview_profile_icon.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  galleryAddPic();
  
              }
          });
  </code></pre>
  
  <p>and </p>
  
  <pre><code>    private void galleryAddPic() {
       String fileName = intentProfilePic.substring(intentProfilePic.lastIndexOf('/') + 1);
       Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
       File f = new File(intentProfilePic);
       Uri contentUri = Uri.fromFile(f);
       mediaScanIntent.setData(contentUri);
       this.sendBroadcast(mediaScanIntent);
       showImage(fileName);
     }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>   public void showImage(String fileName) {
      Intent intent = new Intent();
      intent.setAction(Intent.ACTION_VIEW);
      intent.setDataAndType(Uri.parse("file://" +"/sdcard/"+fileName ), "image/*");
      startActivity(intent);
     }
  </code></pre>
  
  <p>Even i don't know i am doing in right way or wrong.</p>
  
  <p>When i click on imageview my app crashes and error says...</p>
  
  <pre><code> android.os.FileUriExposedException: file:///sdcard/4f5eac461a2a75431d392dd71ffebf97.jpg exposed beyond app through Intent.getData()
  </code></pre>
  
  <p>i know i it is wrong path. so i want to know that how to get file path and also save image. and again open it with onclink using filepath. I also don't know whether it saves file or not.</p>