发送图像在Viber的 [英] Sending Image over Viber
本文介绍了发送图像在Viber的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过Viber的或watzapp发送图像。 WhatsApp的工作正常,但Viber的始终保持告诉选择的文件appearers是不支持或已损坏。请选择一个不同的文件。任何想法是怎么回事?
下面是我的code
开放的URI = Uri.parse(android.resource://com.example.test/drawable/image_1);
sharingIntent.setType(图像/ JPG);
sharingIntent.putExtra(Intent.EXTRA_STREAM,URI);
startActivity(Intent.createChooser(sharingIntent,分享图像使用));
解决方案
INT checkExistence = getResources()则getIdentifier(图像_+位置,绘制,getPackageName());
位图bitmapToShare = BitmapFactory.de codeResource(
getResources(),checkExistence);
文件pictureStorage =环境
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
文件noMedia =新的文件(pictureStorage.nomedia);
如果(!noMedia.exists())
noMedia.mkdirs();
档案文件=新的文件(noMediameme_shared_image.png);
如果(saveBitmapAsFile(bitmapToShare,文件)){
意图shareIntent =新意图(android.content.Intent.ACTION_SEND,Uri.fromFile(文件));
shareIntent.setType(图像/ JPEG);
shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(文件));
startActivity(Intent.createChooser(shareIntent,分享图像使用));
}
其他
{
Toast.makeText(MainActivity.this发送错误,Toast.LENGTH_LONG).show();
} } 私人布尔saveBitmapAsFile(位图bitmapToShare,档案文件){
FileOutputStream中出;
尝试{
OUT =新的FileOutputStream(文件);
bitmapToShare.com preSS(Bitmap.Com pressFormat.JPEG,90出);
返回true;
}赶上(FileNotFoundException异常五){
e.printStackTrace();
返回false;
}
}
固定..希望这有助于在一段时间内另外一个人。 <一href=\"http://stackoverflow.com/questions/25334647/how-to-share-drawable-image-via-viber-and-google-hangout\">how通过Viber的和谷歌的视频群聊,分享绘制的图像?这给我的帮助
I am trying to send a image through viber or watzapp. Whatsapp works fine but viber always keep telling "The selected file appearers to be unsupported or corrupted. Please select a different File". Any idea what's going wrong ?
Here is my code
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"));
解决方案
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;
}
}
Fixed .. hope this help some one else at some time. how to share drawable image via viber and google hangout? This gave me the help
这篇关于发送图像在Viber的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文