Android `settings.db` reference? - android

Is there any reference about settings.db database file?
I see mostly obviously variables but there is not enough for confidence.

On a rooted device, you can pull the file from /data/data/com.android.providers.settings/databases/settings.db (you will need to do adb root before)
Then you can open it a with a sqlite database explorer:
The names are self-explanatory. If one confuses you, a simple google search should help.

There is hardly any reference. You should be using the Settings.System class to be access the system settings in Android. Using the Settings.System class, you are able to both read and write to the system settings.
Checking Mobile Network:
ConnectivityManager nInfo = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
nInfo.getActiveNetworkInfo().isConnectedOrConnecting();
Log.d(tag, "Net avail:"
+ nInfo.getActiveNetworkInfo().isConnectedOrConnecting());
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
Log.d(tag, "Network available:true");
return true;
} else {
Log.d(tag, "Network available:false");
return false;
}

Related

Unable to access isNetworkSupported in android ConnectivityManager class

I am trying use isNetworkSupported(int networkType) to check hardware is support wifi only mode. But it giving error like "The method isNetworkSupported(int) is undefined for the type ConnectivityManager
Following is my code:
ConnectivityManager cm = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean checkStatus = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
Please tell me how we can access this isNetworkSupported method inside our activity.
Thanks.
As per the document, isNetworkSupported is not the method for the class ConnectivityManager.
if you want check internet connection status check this
ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
But I am able to see this method in https://android.googlesource.com/platform/frameworks/base.git/+/android-4.3_r2.1/core/java/android/net/ConnectivityManager.java and in android studio also it is showing this method.
Thanks guys!
After some research and with my colleagues helps I used java reflections to solve this issue
like below.
ConnectivityManager cm = (ConnectivityManager)
this.getSystemService(Context.CONNECTIVITY_SERVICE);
final Class<?> cmlClass = cm.getClass();
String status = "";
try {
final Method wifiCheckMethod = cmlClass.getMethod("isNetworkSupported", int.class);
boolean hasMobileNetwork = (Boolean) wifiCheckMethod.invoke(cm, ConnectivityManager.TYPE_MOBILE);
status = hasMobileNetwork ? "This device has mobile support model" : "This is wifi only model";
Log.i(getClass().getSimpleName(), "The network status is..."+hasMobileNetwork);
} catch (Exception ex) {
ex.printStackTrace();
status = "Error while getting device support model";
}
Toast.makeText(MainActivity.this, "Network support message.."+status, Toast.LENGTH_SHORT).show();

"State.CONNECTED": CONNECTED cannot be resolved or is not a field

I want to check if my Android app is connected to the Internet. I copied the code I read in a book, here it is:
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
int networkType = networkInfo.getType();
android.net.NetworkInfo.State networkState = networkInfo.getState();
if (networkState.compareTo(State.CONNECTED)==0)
{
//We are connected!!!
}
I've also given my app the permission to access network state, but Eclipse says this next to State.CONNECTED:
CONNECTED cannot be resolved or is not a field.
Even books are wrong, now? x(
Thanks in advance.
you have imported the wrong state
change
if (networkState.compareTo(State.CONNECTED)==0)
to
if (networkState.compareTo(android.net.NetworkInfo.State.CONNECTED)==0)

Android - To check if the phone has a network provider

I have an android app, in that there is a particular requirement where in I need to check if the Android device has a network provider or its just WiFi enabled.
Thank You.
This should do the trick.
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if(networkInfo != null && networkInfo.isConnected()){
//Your code here
}
final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo networkInfo = cm.getActiveNetworkInfo();
int type = networkInfo.getType();
String typeName = networkInfo.getTypeName();
boolean connected = networkInfo.isConnected()
networkInfo.getType() will return 0 when connected to Mobile
network or 1 when connected trough WIFI.
networkInfo.getTypeName()
will return the strings mobile or WIFI.
networkInfo.isConnected()
will tell you whether or not you have an active connection.
You should take a look at the documentation.
isProviderEnabled(LocationManager.NETWORK_PROVIDER) is what you need

How to check an IP Address Reachable or not

In my application I have checked whether ineternet connection is there using the below code
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null; }
Now the problem is that how can i check whether conncetion to one remote computer Ip is exist or not...I need to connect to an external IP webservice.....Need to check connetion to that .Suppose the link is like as given below
http://192.168.1.158/VisionEPODWebservice/Manifest.asmx
InetAddress.getByName(ip).isReachable(timeout);
see documentation of InetAddress

Nullpointerexception getSystemService

Following line will only not result in a nullpointer exception if I'm connected to a WLAN:
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Otherwise I get a nullpointer-exception straight ahead? How can I fix this? I want my background service to only work, when it is connected to wlan. But that Nullpointerexception just kills the whole app...
Add to the manifest the following line:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Yes, I am late but in case someone is still looking,
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
no need of Context in the getSystemService() argument.
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.getType() == 1) {
// CONNECTION_WIFI = true;
}

Categories

Resources