gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 09:12:24 24 4
gpt4 key购买 nike

这是我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com