I am trying to get the WiFi passwords programmatically from a non-rooted Android device.
All I need is to be able to read the passwords, I do not need to be able to edit them.
Can I get permission in the manifest file?
I am trying to get the WiFi passwords programmatically from a non-rooted Android device.
All I need is to be able to read the passwords, I do not need to be able to edit them.
Can I get permission in the manifest file?
If your application is a privileged app (that is - installed in /system/priv-app
for example using SuperUser) then you can use the new WifiManager#getPrivilegedConfiguredNetworks()
API in Lollipop and newer.
See: https://android.googlesource.com/platform/frameworks/base/+/758bdf4a915c313f1c3bef0b95b494c91f363f03%5E%21/#F1
This is not possible as this would be a major security risk.
You may be able to if the phone is rooted but I do not know, I would imagine, and hope, even if you could get to where it is stored on the phone, it would be encrypted.
Most of the time, the Wi-Fi credentials are managed by the wpa_supplicant
daemon which store this in a configuration file like /data/misc/wifi/wpa_supplicant.conf
.
In this file you will find network
structures which store the remembered networks like this:
network={
ssid="example"
key_mgmt=WPA-PSK
psk="passphrase"
}
This file is usually own by a system user like wifi
or root
. So you have to be root
if you want to read it directly.
Nevertheless, you can get the ssid
or other network variables of the remember networks by using the wpa_cli
command:
$ wpa_cli get_network <id> ssid
"example"
But if you try with the psk
you will get a *
as this is a security risk:
$ wpa_cli get_network <id> psk
*
There is no API support for reading/writing WiFi passwords for APKs not signed with the system key. So you won't be able to retrieve it.