1
我想包括在我的应用图像共享和一切工作,但份额选择器需要很长时间才能出现在设备分享意图需要较长时间才能显示
这里是我在做什么:
我的ImageView“items_details_image”,我想分享它的图像能够通过WhatsApp的和其他应用程序发送它
void ShareImg() {
try {
Uri bmpUri = getLocalBitmapUri(items_details_image);
if (bmpUri != null) {
// Construct a ShareIntent with link to image
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/*");
// Launch sharing dialog for image
startActivity(Intent.createChooser(shareIntent, "Share Image"));
} else {
// ...sharing failed, handle error
}
} catch (Exception e) {
}
}
这里是如何得到的位图图像从URL
public Uri getLocalBitmapUri(ImageView imageView) {
// Extract Bitmap from ImageView drawable
Drawable drawable = imageView.getDrawable();
Bitmap bmp = null;
if (drawable instanceof BitmapDrawable){
bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
} else {
return null;
}
// Store image to default external storage directory
Uri bmpUri = null;
try {
File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png");
file.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
bmpUri = Uri.fromFile(file);
} catch (IOException e) {
e.printStackTrace();
}
return bmpUri;
}
我不知道为什么它会比平常久其与同一个设备上的其他应用程序,如画廊或任何比较
所以我应该做一个asynctask来维护getLocalBitmapUri? –
@YazanAllahham:更好的是做别的事情。这个'ImageView'从某个地方得到了它的图像。如果“某处”已经存在于“Uri”可到达的位置,则只需使用图像的原始来源。 – CommonsWare
Wooow!太棒了!谢谢。因为我使用的是UniversalImageLoader,所以我可以在ImageLoader的onLoadingComplete事件中使用Image Uri! ...你救了我几个小时! –