Im developing a an android application which is for rooted device.My app is a system app. In the my app i need to all user to input the router ssid,password so that i need to make connection to the router via wifi.

For this im using requestNetowrk method .(android.net.ConnectivityManager.reqeustNetwor(NetworkRequest,NetworkCallback,Timeout)).

It is connected,But after exiting from app the connection lost. How to make the connection remains persist after exiting the app.That i am not needed app level connection and needed device level connection. How to achieve this.

The following are the configurations i used in my app Android 10 & it is system app.

1

There are 1 answers

0
Md Imtiaz Hossain On

You can use addNetwork(WifiConfiguration config) from WifiManager class.

This API is used for persistent connection in Pre-Android Q version. From Android Q it is deprecated, but the deprecation is exempted for Device Owner (DO), Profile Owner (PO) and system apps.

From Android Docs

int addNetwork(WifiConfiguration config)

This method was deprecated in API level 29. a) See WifiNetworkSpecifier.Builder#build() for new mechanism to trigger connection to a Wi-Fi network. b) See addNetworkSuggestions(java.util.List), removeNetworkSuggestions(java.util.List) for new API to add Wi-Fi networks for consideration when auto-connecting to wifi. Compatibility Note: For applications targeting Build.VERSION_CODES.Q or above, this API will always fail and return -1.

Deprecation Exemptions: Device Owner (DO), Profile Owner (PO) and system apps.