我想打開按鈕點擊設備的屏幕上,我使用的代碼是作爲如下屏幕關閉上按鈕點擊
public class MainActivity extends Activity {
Button powerOff;
int amountOfTime =0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
powerOff = (Button)findViewById(R.id.button1);
powerOff.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
// Choice 1
manager.goToSleep(amountOfTime);
// Choice 2
PowerManager.WakeLock wl = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Your Tag");
wl.acquire();
wl.release();
}
});
}
也給出了許可
<uses-permission android:name="android.permission.WAKE_LOCK"/>
儘管如此它示出
01-14 16:06:00.875: E/AndroidRuntime(9317): FATAL EXCEPTION: main
01-14 16:06:00.875: E/AndroidRuntime(9317): java.lang.SecurityException: Neither user 10079 nor current process has android.permission.DEVICE_POWER.
01-14 16:06:00.875: E/AndroidRuntime(9317): at android.os.Parcel.readException(Parcel.java:1322)
01-14 16:06:00.875: E/AndroidRuntime(9317): at android.os.Parcel.readException(Parcel.java:1276)
01-14 16:06:00.875: E/AndroidRuntime(9317): at android.os.IPowerManager$Stub$Proxy.goToSleep(IPowerManager.java:341)
01-14 16:06:00.875: E/AndroidRuntime(9317): at android.os.PowerManager.goToSleep(PowerManager.java:464)
你怎麼解決這個問題? –