Reputation: 471
I am writing an Android app, and would like to have my screen dim after acquiring a wake lock. However, my screen does not dim. It just continues (does not crash) as if nothing happened. I know the wake lock IS begin set because of some test code not shown here. The following is my code:
//Relevant declarations:
PowerManager.WakeLock w1;
PowerManager pm;
public void onClick(View view) {
pm = (PowerManager) getSystemService((Context.POWER_SERVICE));
w1 = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK), "My Tag");
w1.acquire(); //DOES NOT DIM
}
public void onShake () {
if (w1.isHeld())
{
w1.release();
}
//Manifest:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
Any ideas? Thanks.
Upvotes: 1
Views: 1353
Reputation: 1006674
w1.acquire(); //DOES NOT DIM
If you are expecting it to immediately dim, that is not how it works. SCREEN_DIM_WAKE_LOCK
does mean "change the current brightness to dim". It means "we need the screen to be at least dim". Anything else, such as using the device, can cause the screen to go to full brightness.
Upvotes: 4
Reputation: 707
Add the following permission in your manifest:
<uses-permission android:name="android.permission.WAKE_LOCK" />
Upvotes: 1