android - 如何共享 Firebase 数据库中的图像?
问题描述
我已经创建了数据库,并且有图像的 Url,我想在我的应用程序中显示该图像正在运行,但现在我想在 Whatsapp 等中共享该图像。现在我需要在那里更改,因为我不知道,怎么做?
这是我的代码:
@Override
public void onBindViewHolder(@NonNull final myViewHolder holder, int position) {
Picasso.get().load(mdata.get(holder.getAdapterPosition()).getImage()).into(holder.imgView);
holder.shareBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent;
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), holder.imgView.getId());
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) +"/share.png";
FileOutputStream out = null;
File file = new File(path);
try{
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG,100,out);
out.flush();
out.close();
}catch(Exception e){
e.printStackTrace();
}
path = file.getPath();
Uri bmpUri = Uri.parse("file://" + path);
intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, bmpUri);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_TEXT," Hello Your's Images ");
context.startActivity(Intent.createChooser(intent, " Share Images Via"));
解决方案
您可以使用 uri 执行此操作,并尝试实现下一个代码:
Uri imageUri = Uri.parse(pictureFile.getAbsolutePath());
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
//Send to Whattssap
shareIntent.setPackage("com.whatsapp");
//Even you can add text to the image
shareIntent.putExtra(Intent.EXTRA_TEXT, picture_text);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.MakeShortText("Whatsapp have not been installed.");
}
就这样
推荐阅读
- jpeg - 从原始数据中恢复 Jpeg 文件
- python - 随机森林模型 sci kit 学习指定列
- python - 基本脚本上的随机 ImageMagick 错误/“意外令牌”错误
- javascript - BabelJS 和 Webpack 配置以获得最大可能的兼容性
- python - 具有不同 bin 范围的多个图
- react-native - React Native Expo 应用程序:无法使用 Axios 将图像发布到 Imgur
- java - XLSX 下载是损坏的 Apache POI 到带有 ResponseEntity 的 ByteArrayOutputStream
- c - 在 C 中打印字符串时出现异常行为
- c - 使用 libmongoc-1.0 编译 C 程序
- c# - Kotlin 等价于 C# 事件