How do I open a Service from a Broadcastreceiver?

Asked

Viewed 239 times

1

I’m creating an app that intercepts a text message via BroadcastReceiver, more from that I want to receive this text via broadcast open a service. probably this is done via Intent more I can’t do.

1 answer

0


You just need to start the service on onReceive the class that implements Broadcastreceiver:

import meu.pacote.com.o.servico.MinhaClasseServico;

import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver;

public class MeuBroadcastReceiver extends BroadcastReceiver {    
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent serviceIntent = new Intent(this, MinhaClasseServico.class);
        context.startService(serviceIntent);
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.