I'm having a little trouble with declaring a receiver in manifest and getting it to work.

I know since android 8.0 there can't be any implicit broadcast receivers declared in manifest, but it can be explicit receivers declared.

So I declared mine like this in manifest:

<receiver android:name=".util.AppReceiver" android:enabled="true" android:exported="false">
    <intent-filter>
        <action android:name="com.ibermatica.mime.starttracking" />
    </intent-filter>
</receiver>

After that, I install the app in the phone in debug mode and place a breakpoint in the onReceive method, which has this code:

if(intent.getAction() != null){
    switch (intent.getAction()){
        case Util.START_TRACKING:
            Intent i;
            i = new Intent(context, LocationUpdatesService.class);
            context.startService(i);
            break;
        default:
    }
}

So I send the broadcast message from command line having the app in background with this command:

adb shell am broadcast -a com.ibermatica.mime.starttracking

But nothing happens, nor the receiver gets called. What is wrong or what do I have to do to fix this?

Thank you in advance!

Related posts

Recent Viewed