I have made the share text and picture on twitter with the intent ACTION_SEND, my images are accessed from my assets folder, for permission to access these resources have implemented a content provider and assigned permissions have, I tested the action of sharing in android 4.1.2 and running, but when testing with android 4.4 mark me an error and does not filter that you can not add image, text me just add, I did a test changing that image for the drawable and lists the image as a publisher but no longer done by giving adds.
Declaration of my content provider in manifest.xml
<provider
android:name="com.domain.app.helper.ImageProvider"
android:authorities="com.domain.app"
android:grantUriPermissions="true"
android:exported="true"
android:multiprocess="true"
>
</provider>
My content provider class
import java.io.FileNotFoundException;
import java.io.IOException;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
public class ImageProvider extends ContentProvider {
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getType(Uri arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public Uri insert(Uri arg0, ContentValues arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean onCreate() {
// TODO Auto-generated method stub
return false;
}
@Override
public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3,
String arg4) {
// TODO Auto-generated method stub
return null;
}
@Override
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
// TODO Auto-generated method stub
return 0;
}
@Override
public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
AssetManager am = getContext().getAssets();
String file_name = uri.getLastPathSegment();
Log.i("ICP", file_name);
if(file_name == null)
throw new FileNotFoundException();
AssetFileDescriptor afd = null;
try {
afd = am.openFd("images/recipes/" + file_name);
} catch (IOException e) {
e.printStackTrace();
}
return afd;
}
}
Using my content provider in terms of sharing
@SuppressLint("DefaultLocale")
private void share(View v, String nameApp, String infoText, String nameImage) {
try {
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty()){
for (ResolveInfo info : resInfo) {
Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
if (info.activityInfo.packageName.toLowerCase().contains(nameApp) ||
info.activityInfo.name.toLowerCase().contains(nameApp)) {
//fix Facebook only share link
if (info.activityInfo.packageName.toLowerCase().contains("facebook") ||
info.activityInfo.name.toLowerCase().contains("facebook")){
targetedShare.setType("text/plain"); // put here your mime type
targetedShare.putExtra(android.content.Intent.EXTRA_SUBJECT, "The app");
targetedShare.putExtra(android.content.Intent.EXTRA_TEXT, context.getResources().getString(R.string.url_short_app) );
}
else{
///targetedShare.setType( "image/*");
targetedShare.setType( "*/*");
String bodyMsg = infoText + ", " + context.getResources().getString(R.string.firm_shared) +" > " + context.getResources().getString(R.string.url_short_app);
targetedShare.putExtra(Intent.EXTRA_TEXT, bodyMsg);
//this change for test
//Uri uri = Uri.parse("android.resource://"+context.getPackageName()+"/drawable/table");
Uri theUri = Uri.parse("content://"+context.getPackageName()+"/"+nameImage);
targetedShare.putExtra(Intent.EXTRA_STREAM, theUri);
}
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
v.getContext().startActivity(chooserIntent);
}
} catch (Exception e) {
Log.i("ERROR_SHARE", e.toString());
}
}
I hope you can help me find out what the fault have
I'm assuming that android 4.4 has changed the way to access content provider resources