我已经创建了数据库并且有图像的网址,我想在正在运行的应用程序中显示该图像,但是现在我想在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"));
答案 0 :(得分:0)
您可以使用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.");
}
仅此而已