0

I fetch images from Json and display it in a gridview. On select an image, image enlarges to fullscreen and share option is available. As I click on share option, on phones above API 22, loading bar is not dismissing. It works well till Lollipop. Dont know why its not working in Marshmallow.

Here is the code

    public void share(View view){
    // Get access to the URI for the bitmap
    pDialog = new ProgressDialog(Displaydemo.this);
    pDialog.setMessage("Loading...");
    pDialog.show();
    niv1 = (NetworkImageView) findViewById(R.id.imgNetwork);
    Uri bmpUri = getLocalBitmapUri(niv1);
    if (bmpUri != null) {

        pDialog.dismiss();
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
        shareIntent.putExtra(Intent.EXTRA_SUBJECT,"share");
        shareIntent.putExtra(Intent.EXTRA_TEXT,Datas.Address );
        shareIntent.setType("image/*");
        startActivity(Intent.createChooser(shareIntent, "Share Image"));
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Sreepulari
  • 105
  • 1
  • 10

2 Answers2

1

Looks like you are facing mashmallow Runtime permission issue. please refer to this post Android 6: cannot share files anymore?

Also if are using the v4 Support Library u should use ShareCompat for sharing instead https://medium.com/google-developers/sharing-content-between-android-apps-2e6db9d1368b#.wnlh9s3n7

Community
  • 1
  • 1
pipeur10
  • 63
  • 2
  • 6
0

String path = Environment.getExternalStorageDirectory() + File.separator + File.separator +file_name;

File file_ =new File(path);

private void shareFile( File file_) { Intent intentShareFile = new Intent(Intent.ACTION_SEND);

    intentShareFile.setType(URLConnection.guessContentTypeFromName(file_.getName()));
    intentShareFile.putExtra(Intent.EXTRA_STREAM,
            Uri.parse("file://"+file_.getAbsolutePath()));

    startActivity(Intent.createChooser(intentShareFile, "Share File"));


}
Ganesan J
  • 539
  • 7
  • 12