For creating a receiver I'm extended WakefulBroadcastReceiver
in my old project. But now it's deprecated
. Instead of WakefulBroadcastReceiver
which Receiver
I should use now and how to convert below code with new method?
Here is my code:
public class TaskFinishReceiver extends WakefulBroadcastReceiver {
private PowerManager mPowerManager;
private PowerManager.WakeLock mWakeLock;
@Override
public void onReceive(Context context, Intent intent) {
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
turnOnScreen();
Intent wakeIntent = new Intent();
wakeIntent.setClassName("com.packagename", "com.packagename.activity.TaskFinished");
wakeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(wakeIntent);
}
public void turnOnScreen(){
mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
mWakeLock.acquire();
}
}