Android检测手机GPRS是否开启,和开启关闭Android手机GPRS功能的方法

Android检测手机GPRS是否开启,和开启关闭Android手机GPRS功能的方法


	/**
	 * 检测GPRS是否打开
	 * @author YOLANDA
	 * @return
	 */
	public static boolean isGPRSOpen() {
		Boolean isOpen = false;
		try {
			ConnectivityManager connectivityManager = (ConnectivityManager)Application.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE);
			Class<?> cmClass = connectivityManager.getClass();
			Class<?>[] argClasses = null;
			Method method = cmClass.getMethod("getMobileDataEnabled", argClasses);
			Object[] argObject = null;
			isOpen = (Boolean) method.invoke(connectivityManager, argObject);
		} catch (Exception e) {
		}
		return isOpen;
	}

	/**
	 * 开启或者关闭GPRS
	 * @author YOLANDA
	 * @param isEnable
	 */
	public static void setGprsEnable(boolean isEnable) {
		try {
			ConnectivityManager connectivityManager = (ConnectivityManager)Application.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE);
			Class<?> cmClass = connectivityManager.getClass();
			Class<?>[] argClasses = new Class[1];
			argClasses[0] = boolean.class;
			Method method = cmClass.getMethod("setMobileDataEnabled", argClasses);
			method.invoke(connectivityManager, isEnable);
		} catch (Exception e) {
		}
	}


你可能感兴趣的:(Android检测手机GPRS是否开启,和开启关闭Android手机GPRS功能的方法)