android - sending image via intent -
refer page permission part.
i have first app has following :
file imagepath = new file(getapplicationcontext().getfilesdir(), "images"); file newfile = new file(imagepath, "earth.jpg"); uri contenturi = fileprovider.geturiforfile(getapplicationcontext(), "com.android.provider.datasharing", newfile); getapplicationcontext().granturipermission("com.android.datasharing_2.app", contenturi, intent.flag_grant_read_uri_permission); intent = new intent(); i.setaction(intent.action_send); i.putextra(intent.extra_stream, contenturi); i.settype("image/jpg"); startactivity(i);
in manifest :
<provider android:name="android.support.v4.content.fileprovider" android:authorities="com.android.provider.datasharing" android:exported="false" android:granturipermissions="true"> <meta-data android:name="android.support.file_provider_paths" android:resource="@xml/paths"/> </provider>
in receiving app (com.android.datasharing_2.app) :
uri imageuri = (uri) intent.getparcelableextra(intent.extra_stream); if (imageuri != null){ imageview iv = (imageview) findviewbyid(r.id.imageview); iv.setimageuri(imageuri); }
i following message in log in receiving app:
resolveuri failed on bad bitmap uri: content://com.android.provider.datasharing/my_images/earth.jpg java.io.filenotfoundexception: no such file or directory @ android.database.databaseutils.readexceptionwithfilenotfoundexceptionfromparcel(databaseutils.java:146) @ android.content.contentproviderproxy.opentypedassetfile(contentprovidernative.java:682) @ android.content.contentresolver.opentypedassetfiledescriptor(contentresolver.java:1063) @ android.content.contentresolver.openassetfiledescriptor(contentresolver.java:904) @ android.content.contentresolver.openinputstream(contentresolver.java:629) @ android.widget.imageview.resolveuri(imageview.java:659) @ android.widget.imageview.setimageuri(imageview.java:399)
i testing using genymotion vm. push file 'earth.jpg' images folder using adb , can see there.
how resolve ?
the problem location of image. use files-path
, 1 needs put files under files/ directory. images/ directory should have been under there, pushed file @ :
app-dir-path/files/images/earth.jpg
Comments
Post a Comment