可修改系统源码的情况下: 在frameworks/base/services/java/com/android/server/BatteryService.javaIntent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN); intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(intent); 关于ACTION_SHUTDOWN : This is a protected intent that can only be sent by the system.
在frameworks/base/services/java/com/android/server/BatteryService.javaIntent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
关于ACTION_SHUTDOWN :
This is a protected intent that can only be sent by the system.
我查到可以用
Settings.Secure.setLocationProviderEnabled(resolver, LocationManager.GPS_PROVIDER, state);
这个方法开启GPS,而且在android 2.2中已经开放了这个函数。
我在AndroidManifest.xml中也添加了
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
为何我在SDK2.2下运行依然提示:
"java.lang.SecurityException:Permission denial:writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS" ?