0

I am trying to wake the android phone, using PowerManager. However, SCREEN_DIM_WAKE_LOCK seems to be deprecated. Does anyone know how to approach this another way?

public class ShakeToWake extends Activity {

BroadcastReceiver mReceiver;

@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
                PowerManager.WakeLock mWakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "YourServie");
                mWakeLock.acquire();

                Window window = getWindow();
                window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

                mWakeLock.release();
            }

        };
    }

}
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
user3630775
  • 181
  • 3
  • 13
  • I strongly suspect that there was a legitimate reason for the deprecation. Security reasons, perhaps? Or phones lighting up for no apparent reason. – Robert Harvey Jun 01 '14 at 20:54
  • They're doing it in a different way now, that's all. It says what the replacement is in the api docs – Gabe Sechan Jun 01 '14 at 21:47

1 Answers1

0

The docs by google tell you the replacement for it- Most applications should use FLAG_KEEP_SCREEN_ON instead of this type of wake lock, as it will be correctly managed by the platform as the user moves between applications and doesn't require a special permission.

http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_KEEP_SCREEN_ON

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127