我正在尝试使用 SMSManager 在没有用户界面的情况下发送 SMS。在 Android 4.1.2 及以下版本上可以,但在 Android 4.4.2 中不起作用。
这是我的代码:
SmsManager sms = SmsManager.getDefault();
ArrayList<String> msgStringArray = sms.divideMessage(message);
sms.sendMultipartTextMessage(phoneNumber, null, msgStringArray, null,null);
怎么了?
最佳答案
由于 Android 4.4 的变化,您的应用可能无法发送短信。概述于 https://developer.android.com/about/versions/android-4.4.html#SMS你可以看到变化。
SMS Provider The Telephony content provider (the "SMS Provider") allows apps to read and write SMS and MMS messages on the device. It includes tables for SMS and MMS messages received, drafted, sent, pending, and more.
Beginning with Android 4.4, the system settings allow users to select a "default SMS app." Once selected, only the default SMS app is able to write to the SMS Provider and only the default SMS app receives the SMS_DELIVER_ACTION broadcast when the user receives an SMS or the WAP_PUSH_DELIVER_ACTION broadcast when the user receives an MMS. The default SMS app is responsible for writing details to the SMS Provider when it receives or sends a new message.
Other apps that are not selected as the default SMS app can only read the SMS Provider, but may also be notified when a new SMS arrives by listening for the SMS_RECEIVED_ACTION broadcast, which is a non-abortable broadcast that may be delivered to multiple apps. This broadcast is intended for apps that---while not selected as the default SMS app---need to read special incoming messages such as to perform phone number verification.
For more information, read the blog post, Getting Your SMS Apps Ready for KitKat.
关于java - 在 android 4.4.2 中发送没有用户界面的短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23700475/