0

I am Triggering an IntentService from WakefullBroadcastReceiver

    Intent i = new Intent(context, MyService.class);
    i.putExtras(bundle);
    Log.i("StartService","Before Wakelock");
    WakeLock lock = MyService.getLock(context);
    Log.i("StartService","After Wakelock");
    lock.acquire();
    Log.i("StartService","After Aquire");
    context.startService(i);    
    lock.release();
    Log.i("StartService","After Release");

All the above logs are Getting displayed. But My service is not getting called.

IntentService

public class MyService extends IntentService {
private static final String NAME = MyService.class.getName() + ".Lock";
private static volatile WakeLock lockStatic = null;

synchronized public static PowerManager.WakeLock getLock(Context context) {
    if (lockStatic == null) {
        PowerManager mgr = (PowerManager) context
                .getSystemService(Context.POWER_SERVICE);
        lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NAME);
        lockStatic.setReferenceCounted(true);
    }
    return (lockStatic);
}

public MyService(String name) {
    super(name);
}

public MyService() {
    super("MyService");
}

@Override
protected void onHandleIntent(Intent intent) {
    try {
        Log.i("IntentService", "In HandleIntent");
    } finally {

    }

}

}

Can anyone help me??

user3616287
  • 145
  • 1
  • 1
  • 11

1 Answers1

0

In the onCreate() you need to add the flags to the window. For example:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);`
}

I have already posted my here check this

Community
  • 1
  • 1
Kartheek
  • 7,104
  • 3
  • 30
  • 44