Always getting -1 in adding new wifiConfiguration to the wifiiManager

六眼飞鱼酱① 提交于 2019-12-05 17:42:35
HaimS

addNetwork() returns -1 on failure. One common reason for it to fail is when the network was previously configured by the user (through the wifi setting screen) or programmatically, via an app with different Unix User ID (i.e. UID). Recall that every app is associated with a UID.

If the same UID calls addNetwork() for the second time, it will be allowed to override the configuration and the function will succeed.

A similar related behavior is with regards to removing a configuration via the removeNetwork() API. Only the app with the UID that added the configuration can remove it.

This behavior makes sense since you wouldn't want a malicious (or just buggy) app, to override or remove configurations done by either the user or other apps.

So far so good, but there's a complication - when an app is reinstalled (read: uninstalled and then installed again), the OS will provide it with a different UID. Now the same app which previously added the configuration, following the reinstall, can no longer remove or update it. Ouch!

It would have been nice to allow the same application ID to be able to update/remove a network. Oh well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!