How to get Up time in android device programmatically - android

I am working on developing a settings kind of application in android where i need to retrieve the details of the device
I am having difficulty in finding the following
Signal Strength,
Service State
and Up time.
How to find these 3 current values?
Where can i get the sample settings application?

Up-time:
http://developer.android.com/reference/android/os/SystemClock.html#uptimeMillis()
Service State:
http://developer.android.com/reference/android/telephony/ServiceState.html
Signal Strength:
http://developer.android.com/reference/android/telephony/SignalStrength.html#getGsmSignalStrength()
And here's a link to the platform setting:
https://github.com/android/platform_packages_apps_settings/blob/master/src/com/android/settings/deviceinfo/Status.java

public void onReceive(WifiManager wifiManager) {
int numberOfLevels=5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level=WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
System.out.println("Bars =" +level);
}
This may Provide you the Signal Strength there is a refrence Below
How to get signal strength of connected WiFi android?
May be this will help you

Related

How to get Nearby Wifi distance and direction in Android Studios

How can I get the direction and the strength of all the nearby Wifi ?
Till now I have been able to get Wifi Strength in Level but only of connected wifi using following code
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
int numberOfLevels = 5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
I am trying to do something like this
Play Store App Link
This app gives nearby wifi plot on campas
Can anyone guide my how this is possible?
Short answer "not possible".
Long answer is that the phone gives just the strength of the incoming signal, which can come from any direction. You can not even estimate the distance to the WiFi access point until you know its signal strength with your phone for some known distance. You can however estimate the direction of where the WiFi access point is from movement of your phone and the differences of the WiFi signal strength changes.
The app you linked to tells you to start scanning and then slowly rotate. That is needed for recording the device orientation and the signal strength changes. Then based on the orientation of the device and the signal strength for that orientation it can estimated where the WiFi access point is. I am not connected with that app in any way, nor I have used it. All this information is based on the app's screenshots and general knowledge of how WiFi works.
Then there are other funny things like WiFi access points which can send a stronger signal in a specific direction when it detects a device with low signal.
To find distance you can try:
public double calculateDistance(double signalLevelInDb, double freqInMHz) {
double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(signalLevelInDb)) / 20.0;
return Math.pow(10.0, exp);
}

Google Nearby Connection API: measure signal strength

Recently I found a seemingly cool way to communicate between devices using Google Nearby API. Skimming through the documentation didn't answer my question - is it possible to measure the connection signal strength in real time, or should I invent some kludges e.g. measuring time of sending and receiving data or something else?
Thank you.
As a developer of Nearby API stated in thread Google Nearby Messages - Cancel initial link between devices :
Today, Nearby doesn't expose distance directly
He suggests to use BLE RSII instead
You can get a rough approximation of distance by measuring BLE RSSI if one of the devices is capable of BLE advertising. This will be sensitive to how the device is held, antenna gain and environmental factors but better than random.
There's not a straight-forward "tape measure" API, though.
If your question really is about "Nearby Connection API" and not "Nearby Messages API", you could simply check the Wifi-Signal Strength:
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int numberOfLevels = 5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);

How can i get notification on wifi signal strength change?

Requirement in my application is to show Wifi signal strength on wifi signal change.
For a first time i am calculating the Signal strength by following code.
int numberOfLevels=5;
WifiManager wifiManager = (WifiManager)getActivity().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level=WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
I want to update UI frequently if wifi signal is change.
Is there any broadcast available which notify me once signal strength is changed.
Do you any idea How can i achieve this functionality?
Apparently, yes: the broadcast action is "android.net.wifi.RSSI_CHANGED". See WifiManager.RSSI_CHANGED_ACTION
Have never used it personally though.

get dbm wifi signal strength from home access point

I have been trying to create an android application that will give me the signal strength of my home access point from a wireless device e.g. laptop, mobile phone. I have been pulling my hair out with it the last few days and been getting no where. Can someone please give a hand with this because it is really getting on my nerves :( all I want it to do at the minute is display the strength in the console for me, it sounded pretty simple and I have read countless articles and have got nowhere at all :(
You can get the dbm value using WifiManager.
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if(wifiManager.isWifiEnabled()) {
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if(wifiInfo != null) {
int dbm = wifiInfo.getRssi();
}
}
In addition to dbm, if you wish to get the percentage about the signal strength:
int strengthInPercentage = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 100);

Scan all wifi devices near the phone

Company http://renewlondon.com/ have the terminal stations that collect all near by mac addresses
Can I via iOS SDK, and Android SDK,do the same thing?
You can access the wifi data using 'WifiManager' and after the scanning the scanresult contain all the data like
BSSID The address of the access point.
SSID The network name.
capabilities Describes the authentication, key management, and encryption schemes supported by the access point.
frequency The frequency in MHz of the channel over which the client is communicating with the access point.
level The detected signal level in dBm.
timestamp Time Synchronization Function (tsf) timestamp in microseconds when this result was last seen.
about the wifi devices.
if you need more related to coding, I think I can help you...
Sample code
WifiManager wManager;
List<ScanResult> wifiList;
wManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
// Inside BroadcastReceiver()
wifiList = wManager.getScanResults();
for (int i=0; i<wifiList.size(); i++){
ScanResult scanresult = wifiList.get(i);
System.out.println("SSID: "+ssid);
System.out.println("RSSI: "+scanresult.level);
System.out.println("Frequency: "+scanresult.frequency);
System.out.println("BSSID: "+scanresult.BSSID);
System.out.println("Capability: "+scanresult.capabilities);
}
Also checkout the BroadcastReceiver().
One way i can think of doing this is making your device as wifi hotspot and use some hidden api to discover devices.You are basically trying to mimic an access point.
Otherwise each device would need some p2p framework on them-either wifi direct on or some other framework like alljoyn or samsung chord which helps in peer to peer discovery

Categories

Resources