Android send SMS which is visible in SMS thread (no GUI)

戏子无情 提交于 2019-12-17 22:37:20

问题


What I need:
- Send SMS with no GUI interaction (choosing a client to send SMS is out)
- SMS has to be visible in a thread queried from "content://mms-sms/conversations/"+threadId

Currently I'm using SMSManager:

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phone, null, message, null, null);  

Is there any ways to do this across all the devices considering each of them has a different SMS app. Thanks in advance.


回答1:


Just figured it out, you can use ContentResolver to insert the SMS and remember to add permissions: "uses-permission android:name="android.permission.WRITE_SMS"

   ContentValues values = new ContentValues();
   values.put("address", phone);
   values.put("body", message);
   getContentResolver().insert(Uri.parse("content://sms/sent"), values);



回答2:


You need to use the following value:

values.put("thread_id", threadId);

And it will be associated with the thread.



来源:https://stackoverflow.com/questions/3873142/android-send-sms-which-is-visible-in-sms-thread-no-gui

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!