Disable/Enable mobile data on Android L with root access

后端 未结 4 1961
-上瘾入骨i
-上瘾入骨i 2020-12-28 22:02

I am writing a little app that only I will use and I want to pragmatically enable / disable my mobile data on a rooted android 4.5 device (I am running a custom Android L fo

4条回答
  •  青春惊慌失措
    2020-12-28 22:17

    Use this

    TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    Method methodSet = tm.class.getDeclaredMethod( "setDataEnabled", boolean.class);
    methodSet.invoke(tm, true); 
    

    Edit: This requires permission MODIFY_PHONE_STATE, this is System or signature level permission.

    Ideally you could create a runnable jar file with this code and execute it using

    export CLASSPATH=
    exec app_process  your.package.name.classname "$@"
    

    from su shell.

提交回复
热议问题