java - 如何在 RecyclerView 中共享 Firebase 中的图像?

标签 java android database firebase android-recyclerview

这是我在 MainActivity 类中的共享 Intent 。我在 Uri.parse 行收到错误。

     viewHolder.mShareButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent shareIntent = new Intent();
              shareIntent.setAction(Intent.ACTION_SEND);
              shareIntent.putExtra(Intent.EXTRA_TEXT, "Shared via Entrepreneur Quotebook");
              shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(getImageUri(Context ctx,)));

              shareIntent.setType("image/*");
              startActivity(Intent.createChooser(shareIntent, "Share image via:"));

该方法用于解析Uri。我不确定这个方法是否正确,因为我是从某处复制的。

    public Uri getImageUri(Context ctx, Bitmap post_image) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    post_image.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(ctx.getContentResolver(), post_image, "Title", null);
    return Uri.parse(path);

最佳答案

好吧,试试这个:-

public class RecycleClass extends RecyclerView.Adapter<RecycleClass.ViewHolder> { 
    Context c;
    ArrayList<String> yourData = new ArrayList<>();//additional parameters



    RecycleClass(Context c,ArrayList<String> yourData){
      this.c = c; //this is important
      this.yourData = yourData;
    }

    /*
      Rest of your code...
     */
  }

以及您的主要 Activity (或您设置此回收器 View 的 Activity )

//this will setup your context
adapter = new RecycleClass(MainActivity.this,yourData);

并且还要替换这个

startActivity(Intent.createChooser(shareIntent, "Share image via:"));

c.startActivity(Intent.createChooser(shareIntent, "Share image via:"));

最后

public Uri getImageUri(Bitmap post_image) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
post_image.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(c.getContentResolver(), post_image, "Title", null);
return Uri.parse(path);
}

现在,无论您在哪里调用 getImageUri() 方法,都只需传递 Bitmap 而不是上下文。

试试这个,让我知道它是否有效。

关于java - 如何在 RecyclerView 中共享 Firebase 中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40834027/

相关文章:

java - com.fasterxml.jackson.databind.JsonMappingException : No content to map due to end-of-input in Spring Boot App

android - 主题更改不适用于 <4.0,因为它应该

java - 恢复按钮无法进行最后一项 Activity

database - Redshift 中 GROUP BY 后不必要的 DS_BCAST_INNER

python - Django:模型之间的引用

java - 循环遍历 hashmap 以创建具有内部函数的类实例

java - 我需要帮助 : Send a list of bytes with UDP to a Server, o 它适用于有符号/无符号字节

java - 如何更新 Firestore RecyclerView 中的项目?

mysql - 将 MySQL MyISAM 导入 SQL Server

java - 使用 Apache Axis2 和 Rampart 创建 Web 服务客户端