if (Utils.isPackageInstalled(getContext(), "com.whatsapp")) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
Bitmap bitmap = Utils.screenShotBitmap(getActivity());
Utils.saveImage(getActivity(), bitmap, bet.getID() + ".jpeg");
File file = new File(getActivity().getFilesDir(), bet.getID() + ".jpeg");
if (file.exists()) {
Log.i("share", "file exists");
Log.i("share", Uri.fromFile(file).toString());
}
sendIntent.putExtra(Intent.EXTRA_TEXT, "Share text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
sendIntent.setType("image/*");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
}
// ...
public static Bitmap screenShotBitmap(Activity activity) {
return Falcon.takeScreenshotBitmap(activity);
}
public static void saveImage(Context context, Bitmap b, String name){
FileOutputStream out;
try {
out = context.openFileOutput(name, Context.MODE_PRIVATE);
b.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Вход-выход:WhatsApp общий образ только черный
03-25 17:13:24.328 26417-26417/x.x.x I/share: file exists
03-25 17:13:24.328 26417-26417/x.x.x I/share: file:///data/data/x.x.x/files/4b00abc2-7aae-4234-945b-59905306ad4a.jpeg
Bitmap bitmap = Utils.screenShotBitmap(getActivity());
, кажется, работает хорошо, и вернуть правильный Bitmap, потому что я могу поделиться без проблем в facebook.
Будет ли 'FileProvider' работать с Android 4.1? – Chris
@Chris: Он должен работать с API уровня 4 (a.k.a., Android 1.6). – CommonsWare
Я попробую вернуться к вам. Спасибо – Chris