【问题标题】:How to detect sent sms in background in Android如何在Android中检测后台发送的短信
【发布时间】:2020-10-11 10:08:27
【问题描述】:

我正在尝试检测外发短信并计算用户预付余额。所以我如何使用服务来检测每条外发(发送)短信。有人可以帮我吗

【问题讨论】:

    标签: android service background sms contentobserver


    【解决方案1】:

    现在是 SmsSentReceiver。

    public class SmsSentReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent arg1) {
            switch (getResultCode()) {
                case Activity.RESULT_OK:
                    Toast.makeText(context, "SMS Sent", Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    Toast.makeText(context, "SMS generic failure", Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    Toast.makeText(context, "SMS no service", Toast.LENGTH_SHORT)
                    .show();
                    break;
                case SmsManager.RESULT_ERROR_NULL_PDU:
                    Toast.makeText(context, "SMS null PDU", Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    Toast.makeText(context, "SMS radio off", Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    }
    

    现在权限打开您的 AndroidManifest.xml 并添加以下行

    <uses-permission android:name="android.permission.SEND_SMS"/>
    

    【讨论】:

      猜你喜欢
      • 2013-08-20
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      相关资源
      最近更新 更多