使用原生短信应用发送短信,而无需启动本身 [英] Using the native sms app to send an sms without launching itself

查看:158
本文介绍了使用原生短信应用发送短信,而无需启动本身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发短信,但没有使用SmsManager的类。我想与本机的短信应用程序,它是有在Android手机上做到这一点。

I want to send an SMS, but not using the SmsManager class. I want to do it with the native SMS app which is there on an Android phone.

这里是扭曲:我不想启动本机应用程序在做的。有意向的某些格式,可以直接发送短信(给短信体和电话号码,以它来发送)通过本机应用程序(无需点击发送的用户)。

And here is the twist : I do NOT want to launch the native app while doing it. Is there some format of intent which can send an sms directly (given the sms-body and the phone number to send it to) via the native app (without the user having to click 'send').

我用Google搜索相同,但所有的结果和答复干脆推出了原生的短信,等候用户手动发送短信。我已经看到了这个正在实施的像'MightyText一些应用程序,并希望在我的应用程序来实现,以及。

I googled the same, but all results and responses simply launched the native sms, waiting for user to manually send the SMS. I have seen this being implemented in some apps like 'MightyText' and wish to implement in my app as well.

请帮忙!

推荐答案

使用SmsManager的将通过系统发送短信,但不会把它的短信内容提供商如前面提到。因此,任何本地消息的应用程序将无法看到它。

Using the SmsManager will send the sms through the system but will not put it in the SMS content provider as was mentioned earlier. Hence any native messaging app will not see it.

要做到这一点,你有你之后通过SmsManager的正常发送邮件手动通过短信内容提供者进行添加。下面是一些示例code的帮助:

To do so, you have to add it manually via the SMS content provider AFTER you send the message normally via SmsManager. Here's some sample code to help:

ContentValues values = new ContentValues();
values.put("address", "+12345678"); // phone number to send
values.put("date", System.currentTimeMillis()+""); 
values.put("read", "1"); // if you want to mark is as unread set to 0
values.put("type", "2"); // 2 means sent message
values.put("body", "This is my message!");

Uri uri = Uri.parse("content://sms/");
Uri rowUri = context.getContentResolver().insert(uri,values);

而这一切。之后,你会发现,它的加入与本土消息应用程序中显示它正常。

And that's all. After that you'll notice that it's added and the native messaging app displays it normally.

请点击接受的答案,如果它的工作原理为你。

Please click "accept" answer if it works out for you.

这篇关于使用原生短信应用发送短信,而无需启动本身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆