WAKE LOCK REQUIRED FOR BROADCASTRECEIVER PHONE SLEEPS?

sandy taylor

Total Post:46

Points:324
Posted by  sandy taylor
 1232  View(s)
Ratings:
Rate this:
Trying to write a Broadcast Receiver that processes incoming SMSs. Do I need to use a wake lock / partial wake lock, for this application to work, in spite of device going to sleep due to lack of foreground activity ?
  1. Maria Susan

    Post:29

    Points:107
    Re: Wake lock required for BroadcastReceiver phone sleeps?

    I tend to extend a WakefulBroadcastReceiver to simplify things, so in a way yes. For example:

    public class MyBroadcastReceiver extends WakefulBroadcastReceiver
    {
        @Override
        public void onReceive(Context context, Intent intent) {
            final ComponentName comp = new ComponentName(context.getPackageName(),
                    MyIntentService.class.getName());
            // Start the service, keeping the device awake while it is launching.
            startWakefulService(context, (intent.setComponent(comp)));
            setResultCode(Activity.RESULT_OK);
        }
    }

      Modified On Apr-06-2018 06:59:57 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!