问题描述
我正在尝试检测传出的短信并计算用户的预付款余额。因此,我该如何使用服务来检测每条传出的(已发送的)短信。有人可以帮助我吗
解决方法
现在是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"/>