Search code examples
androidcordovaandroid-sharing

Unable to share image in android


I am new in android Java. I am trying to share an image in android application using Phonegap. I get new class "Share" as CordovaPlugin, code is follow...

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
Uri uri = Uri.parse("file:///android_asset/www/sharethis.png");
share.putExtra(Intent.EXTRA_STREAM, uri);
cordova.getActivity().startActivityForResult(share, 0); 

Above code is not working, it showing like this ...

enter image description here

is think i cant get Exact image file location. My file location

enter image description here

I tried bellow code also, But not work,

   String imagePath = Environment.getExternalStorageDirectory()
                + "/assets/www/sharethis.png";

Solution

  • Android asset folder is private to your app so you can't share files from there directly. You need to copy the file from assets to a public directory in the filesystem and then send the share intent pointing to the public file