试了很多种办法,包括:
**
  * 移动网络开关
  */
private void toggleMobileData(Context context, boolean enabled) {
  ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);  Class<?> conMgrClass = null; // ConnectivityManager类
  Field iConMgrField = null; // ConnectivityManager类中的字段
  Object iConMgr = null; // IConnectivityManager类的引用
  Class<?> iConMgrClass = null; // IConnectivityManager类
  Method setMobileDataEnabledMethod = null; // setMobileDataEnabled方法  try {
   // 取得ConnectivityManager类
   conMgrClass = Class.forName(conMgr.getClass().getName());
   // 取得ConnectivityManager类中的对象mService
   iConMgrField = conMgrClass.getDeclaredField("mService");
   // 设置mService可访问
   iConMgrField.setAccessible(true);
   // 取得mService的实例化类IConnectivityManager
   iConMgr = iConMgrField.get(conMgr);
   // 取得IConnectivityManager类
   iConMgrClass = Class.forName(iConMgr.getClass().getName());
   // 取得IConnectivityManager类中的setMobileDataEnabled(boolean)方法
   setMobileDataEnabledMethod = iConMgrClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
   // 设置setMobileDataEnabled方法可访问
   setMobileDataEnabledMethod.setAccessible(true);
   // 调用setMobileDataEnabled方法
   setMobileDataEnabledMethod.invoke(iConMgr, enabled);
  } catch (ClassNotFoundException e) {
   e.printStackTrace();
  } catch (NoSuchFieldException e) {
   e.printStackTrace();
  } catch (SecurityException e) {
   e.printStackTrace();
  } catch (NoSuchMethodException e) {
   e.printStackTrace();
  } catch (IllegalArgumentException e) {
   e.printStackTrace();
  } catch (IllegalAccessException e) {
   e.printStackTrace();
  } catch (InvocationTargetException e) {
   e.printStackTrace();
  }
}
还有
/**   
     * 移动网络开关   
     */   
    public boolean toggleMobileData(Context context, boolean enabled) {     
                    ConnectivityManager cm = (ConnectivityManager) context   
                    .getSystemService(Context.CONNECTIVITY_SERVICE);   
                    Method setMobileDataEnabl;   
                    try {   
                    setMobileDataEnabl = cm.getClass().getDeclaredMethod(   
                    "setMobileDataEnabled", boolean.class);   
                    setMobileDataEnabl.invoke(cm, enabled);   
                    return true;   
                    } catch (Exception e) {   
                    e.printStackTrace();   
                    return false;   
                    }   
    }  
签名和不签名的程序都用了,还是启动不了移动网络。

解决方案 »

  1.   


    Settings.Secure.setLocationProviderEnabled(conText.getContentResolver(), LocationManager.NETWORK_PROVIDER, false);//true 为打开
                Settings.Secure.setLocationProviderEnabled(conText.getContentResolver(), LocationManager.GPS_PROVIDER, false););//true 为打开            Intent i = new Intent(ACTION_SET_USE_LOCATION_FOR_SERVICES);
                i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                i.putExtra(EXTRA_DISABLE_USE_LOCATION_FOR_SERVICES, true);
                conText.startActivity(i);
      

  2.   

    这个是GPS吧? 还是说GPRS也要先执行这段?