Get to now 2G enabled or not : Android | Techbirds
Hi Folks,
Refer this code for identifying your 2G network enabled or not.
int enabled = Settings.Secure.getInt(getContentResolver(), “preferred_network_mode”, -1); Log.d(“MYAPP”, “2G only enabled: ” + enabled); Where the “use only 2G networks” setting is specified as: 0 indicates the setting is disabled 1 indicates the setting is enabled -1 indicates the setting is not set (some devices?) How I discovered this? I gathered all the key/value pairs from Settings.Secure using the following: ContentResolver cr = getContentResolver(); Cursor cursor = cr.query(Settings.Secure.CONTENT_URI, null, null, null, null); if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { Log.d(“MYAPP”, “cursor: ” + cursor.getString(0) + “, ” + cursor.getString(1) + “, ” + cursor.getString(2)); cursor.moveToNext(); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
int enabled = Settings.Secure.getInt(getContentResolver(), “preferred_network_mode”, -1); Log.d(“MYAPP”, “2G only enabled: ” + enabled); Where the “use only 2G networks” setting is specified as: 0 indicates the setting is disabled 1 indicates the setting is enabled -1 indicates the setting is not set (some devices?) How I discovered this? I gathered all the key/value pairs from Settings.Secure using the following: ContentResolver cr = getContentResolver(); Cursor cursor = cr.query(Settings.Secure.CONTENT_URI, null, null, null, null); if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { Log.d(“MYAPP”, “cursor: “ + cursor.getString(0) + “, “ + cursor.getString(1) + “, “ + cursor.getString(2)); cursor.moveToNext(); } } |
Kind Regards,
Tapan Saini
(Android Developer)
542 total views, 1 views today
Share this On