以彩信形式发送图片

发布于 2024-12-02 05:31:10 字数 980 浏览 8 评论 0原文

我正在研究如何从我的应用程序在 android 中发送彩信。

我将名为 image1.png 的图像复制到文件资源管理器中的 sdcard 文件夹中。它位于mnt--> SD卡--> image1.png

我运行模拟器并扫描媒体,我可以在图库中找到该图像。

现在要发送彩信,我使用了以下代码

........................................ ………………………………

    Intent pic = new Intent(Intent.ACTION_SEND);
    pic.putExtra("sms_body", "click the above image");
    String url = "\\sdcard\\image1.png";
    pic.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
    pic.setType("image/png");
    startActivity(pic);

​...................................................... 带有 SD卡

的模拟器已经在运行,现在当我运行应用程序时,它会打开带有 TO 的彩信应用程序字段以及提到的短信正文,但未附加图像。我在屏幕上收到以下 toast 消息

................................. ...................................................... .......

“抱歉,您无法将此图片添加到您的消息中”

................................ ...................................................... ?

任何人都可以帮我解决这个问题吗

我不明白uri的概念。有人可以帮我吗?

非常感谢

I am working on how to send a MMS in android from my app.

i copied an image named image1.png to the sdcard folder in file explorer. its is located in mnt--> sdcard--> image1.png

i run the emulator and scanned the media and i can find the image in the gallery.

now to send the mms i used the following code

...................................................................................

    Intent pic = new Intent(Intent.ACTION_SEND);
    pic.putExtra("sms_body", "click the above image");
    String url = "\\sdcard\\image1.png";
    pic.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
    pic.setType("image/png");
    startActivity(pic);

...................................................................................

the emulator with the sdcard is already running and now when i run the application it opens up the mms apllication with a TO field and also with the sms body mentioned but the image is not attached.i get the following toast message on my screen

...................................................................................

"sorry you cannot add this picture to your message "

...................................................................................

can anyone help me with this issue?

and i dont understand the concept of uri. can someone help me out.

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玉环 2024-12-09 05:31:10

将代码更改为

Intent pic = new Intent(Intent.ACTION_SEND);
pic.putExtra("sms_body", "click the above image");

String external = Environment.getExternalStorageDirectory().toString();
String path = "file://" + external + "/image1.png";

pic.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
pic.setType("image/png");
startActivity(pic);

所以实际上您需要预先附加“file://”

Change your code to

Intent pic = new Intent(Intent.ACTION_SEND);
pic.putExtra("sms_body", "click the above image");

String external = Environment.getExternalStorageDirectory().toString();
String path = "file://" + external + "/image1.png";

pic.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
pic.setType("image/png");
startActivity(pic);

So actually you need to pre-append the "file://"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文