lundi 22 juin 2015

Enable or Disable Mobile Data in Lollipop

      try {
             ConnectivityManager connectivityManager = (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE);
               Method iMthd = ConnectivityManager.class.getDeclaredMethod(
                        "setMobileDataEnabled", boolean.class);
                if (iMthd != null) {
                    iMthd.setAccessible(false);
                    iMthd.invoke(connectivityManager, enable);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

Upto kitkat above mechanism is working properly but in lollipop it is not worked out is there any other way to achieve this.





Aucun commentaire:

Enregistrer un commentaire