我正在尝试使用PowerManager唤醒Android手机。但是,SCREEN_DIM_WAKE_LOCK似乎已被弃用

时间:2014-06-01 20:53:31

标签: android android-intent android-activity wakelock android-wake-lock

我正在尝试使用PowerManager唤醒Android手机。但是,SCREEN_DIM_WAKE_LOCK似乎已被弃用。有谁知道如何以另一种方式接近?

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();
            }

        };
    }

}

1 个答案:

答案 0 :(得分:0)

谷歌的文档告诉你替换它 - 大多数应用程序应该使用FLAG_KEEP_SCREEN_ON而不是这种类型的唤醒锁,因为当用户在应用程序之间移动并且不需要时,它将由平台正确管理特许。

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