这是我在Android应用程序服务中使用的代码。
Android 4.3:它运行得非常好,我可以获得两个待定意图。
Android 4.4+:它发送短信,我能够得到"短信发送"广播消息,但没有得到" SMS已交付"广播。我的应用程序中没有收到短信。只是使用smsmanager发送出去。但我需要跟踪短信是否已发送。如果我在这里遗漏任何东西,请告诉我,
谢谢,
以下是我在服务中使用的代码:
***code I am using to send sms***
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(getBaseContext(), 0, new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(getBaseContext(), 0, new Intent(DELIVERED), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
***boradcast receiver for SMS SENT intent***
sendBroadcastReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Log.d(TAG, "SMS Activity: SMS Sent");
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Log.d(TAG, "SMS Activity: ERROR (GENERIC FAILURE)");
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Log.d(TAG, "SMS Activity: ERROR (NO SERVICE)");
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Log.d(TAG, "SMS Activity: ERROR (NULL PDU)");
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Log.d(TAG, "SMS Activity: ERROR (RADIO OFF)");
break;
default:
Log.d(TAG, "SMS Activity: DEFAULT");
break;
}
}
};
***code for sms delivery intent broadcast receiver***
deliveredBroadcastReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context arg0, Intent arg1) {
Log.d(TAG,"SMS DELIVERY INTENT RECEIVED");
switch (getResultCode())
{
case Activity.RESULT_OK:
Log.d(TAG,"SMS DELIVERY: OK");
break;
case Activity.RESULT_CANCELED:
Log.d(TAG,"SMS DELIVERY: CANCELED");
break;
}
}
};
***Registering the receivers on Start Service()***
registerReceiver(sendBroadcastReceiver , new IntentFilter("SMS_SENT"));
registerReceiver(deliveredBroadcastReceiver , new IntentFilter("SMS_DELIVERED"));
***Unregistering the receivers on Stop Service()***
unregisterReceiver(sendBroadcastReceiver);
unregisterReceiver(deliveredBroadcastReceiver);
答案 0 :(得分:0)
SMS在4.4中发生了显着变化,请参阅https://developer.android.com/about/versions/android-4.4.html#SMS
只有默认的SMS提供商才会收到SMS_DELIVER_ACTION和其他几个事件。我认为你正在打击这些案件。