Skip to content

Instantly share code, notes, and snippets.

@Mirochiu
Created February 4, 2020 03:27
Show Gist options
  • Save Mirochiu/8da2e6884d1ec518b3fb86121f674a20 to your computer and use it in GitHub Desktop.
Save Mirochiu/8da2e6884d1ec518b3fb86121f674a20 to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.content.ContentResolver;
import android.provider.Settings;
import android.content.res.Resources;
private void readSomething() {
try {
Context mContext = getApplicationContext();
ContentResolver mContextRes = mContext.getContentResolver();
String defaultIme = Settings.Secure.getString(mContextRes, Settings.Secure.DEFAULT_INPUT_METHOD);
Log.i(TAG, "Settings.Secure.DEFAULT_INPUT_METHOD = " + defaultIme);
String defaultDnsServer = Settings.Global.getString(mContextRes, Settings.Global.DEFAULT_DNS_SERVER);
Log.i(TAG, "Settings.Global.DEFAULT_DNS_SERVER = " + defaultDnsServer);
final Resources res = mContext.getResources();
/*
String myIME = res.getString(com.android.internal.R.string.config_default_input_method);
Log.i(TAG, "com.android.internal.R.string.config_default_input_method = " + myIME);
*/
String myDns = res.getString(com.android.internal.R.string.config_default_dns_server);
Log.i(TAG, "com.android.internal.R.string.config_default_dns_server = " + myDns);
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void writeSomething() {
try {
Context mContext = getApplicationContext();
ContentResolver mContextRes = mContext.getContentResolver();
boolean isOkay;
final String setupDnsServer = "8.8.8.8";
Log.i(TAG, "setup Settings.Global.DEFAULT_DNS_SERVER = " + setupDnsServer);
isOkay = Settings.Global.putString(mContextRes, Settings.Global.DEFAULT_DNS_SERVER, setupDnsServer);
Log.i(TAG, isOkay?"setup okay!":"setup failed!");
}
catch (Exception e)
{
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment