Im using the solution of this website: 
http://www.nowherenearithaca.com/2012/03/too-easy-using-contentprovider-to-send.htmlto
 share images from assets folder, but it is not working. The share panel 
is being opened, but when i select gmail, google+ or some other social 
sharing network, the image is not being shared.

The method public AssetFileDescriptor openAssetFile(Uri uri, String mode)is not 
being called when i try to share an image, and the image is not 
being shared.

Logcat tells this: No content provider found for permission check: 
content:/com.appname/img319030.jpg

I created a class called AssetsContentProvider on my com.appname.utilpackage 
and i added this line to my manifest:

<provider android:name="com.appname.util.AssetsContentProvider" 
android:authorities="com.appname"/>

The class that is trying to use ACTION_SEND to share the image is located 
on the package com.appname.actions, and it simply does this:

    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("image/jpg");
    Uri theUri = Uri.parse("content:/com.appname/img319030.jpg");
    shareIntent.putExtra(Intent.EXTRA_STREAM,theUri);
    
SectionManager.getCurrentActivity().startActivity(Intent.createChooser(shareIntent,
 ""));


The image is called img319030.jpg and it is located in assets folder.

This is my AssetsContentProvider class:

public class AssetsContentProvider extends ContentProvider{ 
    @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;//super.openAssetFile(uri, mode);
    }   

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        return 0;
    }
    @Override
    public String getType(Uri uri) {
        return null;
    }
    @Override
    public Uri insert(Uri uri, ContentValues values) {
        return null;
    }
    @Override
    public boolean onCreate() {
        return false;
    }
    @Override
    public Cursor query(Uri uri, String[] projection, String selection, 
String[] selectionArgs, String sortOrder) {
        return null;
    }
    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] 
selectionArgs) {
        return 0;
    }}

 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to