java - 在 android 4.4.2 中发送没有用户界面的短信

标签 java android smsmanager

我正在尝试使用 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/

相关文章:

android - 如何将 AdMob 广告集成到适用于 Android 和 iOS 的 Cordova 项目中?

java - Android 模拟器中的新地理修复中的位置未更新

java - 如何将两个 SmsMessage 合并为一个 SmsMessage?

android - 尽管尝试了一切,SMSManager 仍返回 RESULT_ERROR_GENERIC_FAILURE

java - 从JAVA中的h264编码视频中获取SPS和PPS

java - Andengine:区分 OnAreaTouched 和 OnSceneTouched

java - JGraphT - 最大独立集

android - 如何将 cordova 项目从 visual studio (Hybrid App) 编译到 android/ios apk

android - 如何知道从 Android BroadcastReceiver 发送/传递了哪些 Sms?

: List<Object o, 对象内有两个对象的 Java 列表