Android唤醒锁

时间:2016-02-10 21:06:50

标签: android screen

我遇到了唤醒锁问题。我遵循了这个:http://developer.android.com/reference/android/os/PowerManager.html和其他一些教程。我有启动其他活动的待定意图。在这里,我需要唤醒显示器,以便用户完成一些工作。但是,使用下面的代码,显示屏很暗,媒体播放器正在播放。你能告诉我我做错了吗?

待定意图

public class AlarmReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Intent lightIntent = new Intent(context, lightWakeup.class);
    lightIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //volani aktivity z broadcast receiveru
    context.startActivity(lightIntent);
}

}

lightWakeup.class

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_light_wakeup);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
    wl.acquire();
    //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //setSupportActionBar(toolbar);
    text = (TextView)findViewById(R.id.textView);
    //zapnuti hudby

    MainPage.mp.setVolume(100, 100);
    MainPage.mp.setLooping(true);
    MainPage.mp.start();

    sensorManager = (SensorManager) getSy..

清单:<uses-permission android:name="android.permission.WAKE_LOCK">

1 个答案:

答案 0 :(得分:0)

这有帮助

KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
final KeyguardManager.KeyguardLock kl = km.newKeyguardLock("MyKeyguardLock");
kl.disableKeyguard();

PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
        | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
wakeLock.acquire();