Reputation: 961
I was wondering what is wrong in my code bellow ? why the image in Asset was not loaded to facebook share page?
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///android_asset/images/end_level_10.png"));
share.putExtra(Intent.EXTRA_SUBJECT, "Congratulation! You get A+ with Kid IQ Game.");
share.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=kids.iq.kidsiqpicturesquestion");
startActivity(Intent.createChooser(share, "Congratulation!"));
appreciate for your kindly help!
Upvotes: 1
Views: 1137
Reputation: 654
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///android_asset/images/end_level_10.png"));
change the above code to
share.setType("image/png");
or
share.setType("image/*");
Upvotes: 0
Reputation: 6406
It is possible to share files (images including) from the assets folder through a custom ContentProvider
You need to extend ContentProvider
, register it in your manifest and implement the openAssetFile method. You can then assess the assets via Uris.
add this to your manifest
<provider android:name="yourclass.that.extendsContentProvider"
android:authorities="com.yourdomain.whatever"/>
example class,
@Override
public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
AssetManager am = getContext().getAssets();
String file_name = uri.getLastPathSegment();
if(file_name == null)
throw new FileNotFoundException();
AssetFileDescriptor afd = null;
try {
afd = am.openFd(file_name);
} catch (IOException e) {
e.printStackTrace();
}
return afd;
}
for refrence , too-easy-using-contentprovider-to-send
Upvotes: 1