怎么实现关机,关闭gprs ?好像没有提供api,有人说可以用隐藏api,怎么实现?

解决方案 »

  1.   

    可修改系统源码的情况下:
    在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.
      

  2.   

    谢谢。最近在写一个程序,用短信关闭 开启wifi,gps, gprs,关机。貌似都要使用隐藏API...请问一下有没有其他方法可以开启gps?
    我查到可以用
    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" ?