我想通过单击片段中的按钮发送Bitmap
和一些文本,我想让用户在他的消息应用程序中选择联系人/号码。
我怎么能这样做?
编辑:
尝试了一些东西后,我在消息应用程序(模拟器上的 Messenger(中出现错误:
信使无法加载附件。
这是我使用的代码:
String path = Environment.getExternalStorageDirectory().getPath() + "/Improov/LatestShare.png";
File file = new File(path);
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
Uri photoURI = FileProvider.getUriForFile(getContext(), getContext().getApplicationContext().getPackageName() + ".com.example.mous.improov_flash", file);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", message);
intent.putExtra(Intent.EXTRA_STREAM, photoURI);
intent.setType("image/jpeg");
getActivity().startActivity(intent);
如果您想发送彩信,
首先,您应该将位图存储在 SD 卡中,然后使用以下意图发送彩信,
获取存储位图的 Uri
Uri uri = [uri for your stored bitmap];
Intent intent = new Intent(Intent.ACTION_SEND);
inetnt.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra("sms_body", [Text to be send]);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/jpeg");
getActivity.startActivity(intent);
有关更多详细信息,请阅读此官方文档