我正在尝试通过viber或watzapp发送图像。 Whatsapp工作正常,但viber始终在告诉"选定的文件显示不受支持或损坏。请选择其他文件"。知道出了什么问题吗?
这是我的代码
Uri uri = Uri.parse("android.resource://com.example.test/drawable/image_1");
sharingIntent.setType("image/jpg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
答案 0 :(得分:1)
int checkExistence = getResources().getIdentifier("image_"+position, "drawable", getPackageName());
Bitmap bitmapToShare = BitmapFactory.decodeResource(
getResources(), checkExistence);
File pictureStorage = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File noMedia = new File(pictureStorage, ".nomedia");
if (!noMedia.exists())
noMedia.mkdirs();
File file = new File(noMedia, "meme_shared_image.png");
if (saveBitmapAsFile(bitmapToShare, file)) {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND, Uri.fromFile(file));
shareIntent.setType("image/jpeg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(Intent.createChooser(shareIntent, "Share image using"));
}
else
{
Toast.makeText(MainActivity.this, "Sending Error", Toast.LENGTH_LONG).show();
}
}
private boolean saveBitmapAsFile(Bitmap bitmapToShare, File file) {
FileOutputStream out;
try {
out = new FileOutputStream(file);
bitmapToShare.compress(Bitmap.CompressFormat.JPEG, 90, out);
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
}
修正..希望这会在某个时候帮助其他人。 how to share drawable image via viber and google hangout?这给了我帮助