Skip to content Skip to sidebar Skip to footer

How To Share Image To Facebook Via Intent

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/

Solution 1:

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

<providerandroid:name="yourclass.that.extendsContentProvider"android:authorities="com.yourdomain.whatever"/>

example class,

@Overridepublic AssetFileDescriptor openAssetFile(Uri uri, String mode)throws FileNotFoundException {
        AssetManageram= getContext().getAssets();
        Stringfile_name= uri.getLastPathSegment();

        if(file_name == null) 
            thrownewFileNotFoundException();
        AssetFileDescriptorafd=null;
        try {
            afd = am.openFd(file_name);
        } catch (IOException e) {
            e.printStackTrace();
        }

return afd;
}

for refrence , too-easy-using-contentprovider-to-send

Solution 2:

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/*");  

Post a Comment for "How To Share Image To Facebook Via Intent"