tags:

views:

82

answers:

1

I'm trying to create an app and I'm nearly complete. I have been trying to figure out how to either put the phone into sleep mode, which would also lock the screen or just lock the screen.

This is how I am currently trying to accomplish this using the PowerManager.

try{
            PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
            PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "FACEDOWN_LOCK");
            wl.acquire();
                // ? Perform operations
                pm.goToSleep(SystemClock.uptimeMillis());
            wl.release();
        }catch(Exception e){
             Toast.makeText(this, e.getMessage() , 10000).show();
        }

This does NOT work. It gives me permission problems even though my app is signed and I have the permissions enabled in the manifest.xml

<permission android:name="android.permission.WAKE_LOCK" />
    <permission android:name="android.permission.DEVICE_POWER" />
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.DEVICE_POWER" />

Is there a proper way to do this? Can it even be done? Any help would be awesome. I have not been able to find any solution as to how you get the phone to lock or go to sleep.

A: 

I believe the permission DEVICE_POWER has been removed in the recent SDK's to be accessed by 3rd party apps. I found a few more users complaining about this issue.

http://groups.google.com/group/android-discuss/browse_thread/thread/3c4222f55e22b75c

http://markmail.org/message/cnnuaplbgh5bm42s#query:related%3Acnnuaplbgh5bm42s+page:1+mid:dtepkqeoojgvyw2t+state:results

Rahul