Broadcast in service does not work

0

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)

    @Override
    public void onCreate() {
    super.onCreate();
    Log.d(TAG, "ON_CREATE");
    IntentFilter fp = new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION);
    //fp.addAction("android.provider.Telephony.SMS_RECEIVED");
    MRB = new MessageReceiver(); // -> broadcast propio
    registerReceiver(MRB,fp,Manifest.permission.BROADCAST_SMS,null);

}

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

The broadcast

public class MessageReceiver extends BroadcastReceiver {
@Override
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);
            context.startActivity(call);
        }
    }
}

}

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

        <receiver
        android:name=".MessageReceiver"
        android:permission="android.permission.BROADCAST_SMS">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>

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
source

0 answers