我创建了2个广播接收器,一个获得SMS发送状态,另一个获得传送状态!每个都在清单文件中注册!直到nogout,一切都很好!现在在奥利奥接收器没有被调用!我发现Oreo有背景限制!我想知道我该如何解决这个问题! 我的清单是:
<receiver
android:name="com.arafa.atlink.receiver">
<intent-filter>
<action android:name="SMS_SENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.arafa.atlink.deliverreceiver">
<intent-filter>
<action android:name="SMS_DELIVERED" />
</intent-filter>
</receiver>
广播接收者:
public class receiver extends BroadcastReceiver {
PreferenceHelper prefs;
@Override
public void onReceive(Context context, Intent intent) {
String message = null;
prefs = new PreferenceHelper(context);
Log.e("DATA FROM BROADCAST", "++++++++++++++++++++++++++ SmsSentReceiver "+ intent.getExtras().getInt("ucode") +" +++++++++++++++++++++++++++++++++++++++++");
switch (getResultCode()) {
case Activity.RESULT_OK:
message = "Message sent for "+intent.getExtras().getInt("ucode");
Log.e("DATA", message);
pingserversend(intent.getExtras().getInt("ucode"),"Send");
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
message = "Error. Message not sent.";
Log.e("DATA", message);
pingserversend(intent.getExtras().getInt("ucode"),"Failed");
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
message = "Error: No service.";
Log.e("DATA", message);
pingserversend(intent.getExtras().getInt("ucode"),"no-service");
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
message = "Error: Null PDU.";
Log.e("DATA", message);
pingserversend(intent.getExtras().getInt("ucode"),"null-pdo");
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
message = "Error: Radio off.";
Log.e("DATA", message);
pingserversend(intent.getExtras().getInt("ucode"),"radio-off");
break;
}
}
}
正在广播:
Intent intentSent = new Intent(Constants.SMS_SENT);
intentSent.putExtra("ucode", ucode);
PendingIntent piSend = PendingIntent.getBroadcast(this, ucode, intentSent, PendingIntent.FLAG_ONE_SHOT);