我无法通过意图将图像和视频发送到whatsapp。可以同时发送它们吗?
我一直在研究如何做,但是我只找到其中之一的答案。据我所知,我问用户是发送一组图像还是一组视频。另外,我想发送一个字幕(仅一个),但它会重复每个项目的字幕。
ArrayList<Uri> imageUriArray = new ArrayList<>();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
// intent.putExtra(Intent.EXTRA_TEXT, "Text caption message!!");
//intent.setType("text/plain");
//
/* StringBuilder builder = new StringBuilder();
builder.append("Info: \n")
.append("lote: " + mNota.getCod_lote())
.append("" + )*/
String extra_ = "Ubicación: (Lat:"+mNota.getLat()+" ,Lon:"+mNota.getLon()+")" + " \n"
+ "Lote: " + mNota.getCod_lote() +" \n"
+ "fecha: " + fecha + " \n"
+ fieldNota.getText().toString();
intent.setPackage("com.whatsapp");
View radio = getLayoutInflater().inflate(R.layout.radiogroup_wsp, null, false);
//RadioGroup radioGroup = radio.findViewById(R.id.radioGW);
//intent.putExtra(Intent.EXTRA_TEXT, new ArrayList<String>(){{add(extra_);}});
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
RadioButton info = radio.findViewById(R.id.btnSendInfo);
RadioButton vids = radio.findViewById(R.id.btnSendVideos);
RadioButton pics = radio.findViewById(R.id.btnSendPhotos);
new AlertDialog.Builder(mContext)
.setTitle("Enviar a Whatsapp..")
.setMessage("Eliga una opción: ")
.setView(radio)
.setCancelable(true)
.setPositiveButton("Enviar", (dialogInterface, i) -> {
try {
if (vids.isChecked()) {
List<mediaHolder> videos = mVideoAdapter.getVideos();
for (mediaHolder video :
videos) {
//imageUriArray.add(Uri.fromFile(new File(video.getPathFile())));
imageUriArray.add(FileProvider.getUriForFile(mContext,mContext.getApplicationContext().getPackageName(),new File(video.getPathFile())));
}
intent.setType("video/mp4");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUriArray);
startActivity(intent);
} else if (pics.isChecked()) {
List<mediaHolder> photos = mPicturesAdapter.getPictures();
for (mediaHolder photo :
photos) {
//imageUriArray.add(Uri.fromFile(new File(photo.getPathFile())));
imageUriArray.add(FileProvider.getUriForFile(mContext,mContext.getApplicationContext().getPackageName(),new File(photo.getPathFile())));
}
intent.setType("image/*");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUriArray);
startActivity(intent);
}else if (info.isChecked()) {
intent.putExtra(Intent.EXTRA_TEXT,extra_);
intent.setType("text/plain");
startActivity(intent);
}else {
Toast.makeText(mContext, "No se seleccionó una opción.", Toast.LENGTH_SHORT).show();
}
}catch (Exception ex){
ex.printStackTrace();
Toast.makeText(mContext, "Error Message: " + ex.getMessage(), Toast.LENGTH_SHORT).show();
}
})
//.setPositiveButtonIcon(mContext.getDrawable(R.drawable.ic_send))
.show();
它看起来并不友好。我想至少同时发送它们(图像和视频)。标题是多余的,但非常有用。