Broadcast in service does not work


I tell you, I have android 8, so the broadcasts do not work declared from the manifest and that's why I have to insert them programmatically ...

The process is easy, I show you my service where I add it (extends from Service)

    public void onCreate() {
    Log.d(TAG, "ON_CREATE");
    IntentFilter fp = new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION);
    MRB = new MessageReceiver(); // -> broadcast propio


and in the onDestroiy () you 'deregister' it, the service starts with the application.

The broadcast

public class MessageReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
    Bundle data = intent.getExtras();
    Log.d("Mensaje", "Entra");
    Object[] pdus = (Object[]) data.get("pdus");
    for (int i = 0; i < pdus.length; i++) {
        SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
        String message = "Sender : " + smsMessage.getDisplayOriginatingAddress()
                + "Email From: " + smsMessage.getEmailFrom()
                + "Emal Body: " + smsMessage.getEmailBody()
                + "Display message body: " + smsMessage.getDisplayMessageBody()
                + "Time in millisecond: " + smsMessage.getTimestampMillis()
                + "Message: " + smsMessage.getMessageBody();
        String number = smsMessage.getDisplayOriginatingAddress();
        String id = message.substring(message.length());
        Log.d("Mensaje", message + "Number: " + number + "id+" + id);
        if (message.contains("<BITNODE>")) {
            Log.d("Mensaje", message + "Entre");
            Intent call = new Intent(context, cc_mensaje_entrante.class);
            call.putExtra("number", number);
            call.putExtra("id", id);


The idea of this is that when a special message arrives, raise an activity. Previously, in phones with android less than 8, it worked from the manifest with

            <action android:name="android.provider.Telephony.SMS_RECEIVED" />

But I already try in all possible ways, and I do not give with the error, the server executes, it does not give any error when registering the broadcast, but it never executes ...

asked by LcsGrz 15.11.2018 в 14:10

0 answers