i spand vài giờ để tìm giải pháp này ...Chia sẻ hình ảnh với ShareActionProvider từ Picasso
vì vậy tôi quyết định chia sẻ informatiom này, có thể một số một itwill hữu ích :)
Các Cách thứ nhất, thể hiện bên dưới, lấy bitmap từ khung nhìn và tải nó vào một tập tin.
// Get access to ImageView
ImageView ivImage = (ImageView) findViewById(R.id.ivResult);
// Fire async request to load image
Picasso.with(context).load(imageUrl).into(ivImage);
và sau đó giả sử sau khi hình ảnh đã hoàn thành tải, đây là cách bạn có thể kích hoạt một phần:
// Can be triggered by a view event such as a button press
public void onShareItem(View v) {
// Get access to bitmap image from view
ImageView ivImage = (ImageView) findViewById(R.id.ivResult);
// Get access to the URI for the bitmap
Uri bmpUri = getLocalBitmapUri(ivImage);
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
}
}
// Returns the URI path to the Bitmap displayed in specified ImageView
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;
}
Hãy chắc chắn để thêm các điều khoản thích hợp để AndroidManifest.xml của bạn:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Stack Overflow dành cho lập trình ** câu hỏi **. Đây không phải là một câu hỏi. Nếu bạn muốn trả lời câu hỏi của riêng bạn, điều đó là tốt, nhưng xin vui lòng ** đặt một câu hỏi **. [Tài liệu trang web] (https://stackoverflow.com/help/self-answer) có thêm thông tin về việc trả lời các câu hỏi của riêng bạn. – CommonsWare
Tôi xin lỗi .. Tôi có qeustion này vài giờ trước và tôi không thể tìm thấy câu trả lời trên stackowerflow, vì vậy quyết định sửa chữa nó –
Bạn tôi đang sử dụng nhưng chia sẻ ID hình ảnh sai, bạn có vấn đề này không? Nó đang sử dụng một firebaserecyclerview, với Picasso –