Set static IP and gateway programmatically in Android 6.x (Marshmallow)

后端 未结 3 794
孤独总比滥情好
孤独总比滥情好 2020-12-15 07:46

Can anybody tell me how can I set the static IP and gateway programmatically in Android 6?

I have read here and here.

Settings.System is not working anymore

3条回答
  •  旧时难觅i
    2020-12-15 08:16

    I've dug some into the problem and my findings is that code that used to work for Andrdoi 5.x might work if the application is set to be the device owner.

    Solution:

    The solution is to add the device as deviceOwner. This will allow for static IP to be set using the 5.x hacks as referenced by Mogi. A good example of how this is done is using the example found here:

    https://github.com/googlesamples/android-DeviceOwner/

    Using adb shell and running the command:

    dpm set-device-owner com.example.android.deviceowner/.DeviceOwnerReceiver
    

    will make it ready to be allowed to do its job.

提交回复
热议问题