画像を FileProvider で共有したいのですが、Whatsapp、Dropbox では機能しますが、facebook、google + などがクラッシュします。これが私のソースコードです。私はそれを少し単純化しました: 私のマニフェスト
ファイルプロバイダーが空です:
public class MyFileProvider extends FileProvider {
}
私の共有クラス:
public class Sharing extends AsyncTask<String, String, Intent> {
Context cont;
public Sharing(Context cont) {
this.cont = cont;
}
@Override
protected Intent doInBackground(String... arg0) {
try {
Bitmap b = BitmapFactory.decodeResource(cont.getResources(), R.drawable.ic_launcher);
saveFile(cont, b);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/jpg");
Uri uri = getImageUri(cont);
List<ResolveInfo> resInfoList = cont.getPackageManager()
.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
cont.grantUriPermission(packageName, uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
intent.putExtra(Intent.EXTRA_STREAM, uri);
return intent;
} catch (Exception e) {
Log.e("shareerror", e.toString());
e.printStackTrace();
return null;
}
}
public void saveFile(Context inContext, Bitmap inImage) throws Exception {
File cacheDir = inContext.getCacheDir();
File outFile = new File(cacheDir+"screenshot.jpg");
FileOutputStream out = new FileOutputStream(outFile.getAbsolutePath());
inImage.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.close();
}
public Uri getImageUri(Context incontext) {
File cacheDir = incontext.getCacheDir();
File urifile = new File(cacheDir, "screenshot.jpg");
Uri photoUri = MyFileProvider.getUriForFile(incontext,
"com.example.sharetest.MyFileProvider", urifile);
return photoUri;
}
public void onPostExecute(Intent shareintent) {
cont.startActivity(shareintent);
}
および file_path.xml
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="photo_cache" path="/"/>
誰かが間違いを見ますか?ありがとうございました :)