我是 Android 新手,必须添加通过短信发送图像、视频的选项。
目前我找到了两种方法:
val sendIntent = Intent(Intent.ACTION_SEND) // 在下面的行中将额外的内容作为短信正文,其中包含编辑文本中的数据 sendIntent.putExtra("sms_body", msgEdt!!.getText().toString()) // 在下面一行将额外内容作为图像 uri sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imageUri)) // 在下面一行设置意图类型。 sendIntent.setType(“图片/png”) // 在下面的行中启动发送短信的活动。 启动活动(发送意图) 在此打开选择发送位置的选项
通过RCS(Google API)发送但找不到如何使用。
有人可以帮我提供代码片段来实现相同的功能吗?过去两周我一直陷入这个困境。
提前致谢
您可以尝试以下代码:
public static void sendMMSWithImage(Context context, Uri imageUri, String phoneNumber, String messageText) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("address", phoneNumber);
intent.putExtra("sms_body", messageText);
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
intent.setType("image/jpeg"); // Change the MIME type based on your image type
// Start the messaging app
context.startActivity(Intent.createChooser(intent, "Send MMS"));
}