How do I open a Service from a BroadcastReceiver?

1

I am creating an application that intercepts an sms via BroadcastReceiver , but from that I want to receive a sms via broadcast open service . probably this is done via Intent but can not do.

    
asked by anonymous 01.03.2015 / 06:24

1 answer

0

You only need to start the service on the onReceive of 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);
    }
}
    
01.03.2015 / 11:05