suggest me source code. My source code is
TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
if(manager.getNetworkType()==TelephonyManager.NETWORK_TYPE_UMTS){
// tx.setText("Edge");
//int enabled = Settings.Secure.getInt(getContentResolver(),
// "preferred_network_mode", -1);
cm.setNetworkPreference(TelephonyManager.NETWORK_TYPE_EDGE);
cm.startUsingNetworkFeature(TelephonyManager.NETWORK_TYPE_EDGE, "Deneme");
}
You cannot do this as it is a restricted setting. You need a special permission, to change it. Take a look at this post.
There is no exported to the SDK functionality to switch between 2G and 3G. For a given device you could probably figure out the private functionality, but it wouldn't work unless the app was signed with the system key.
You can disable the radios though, by turning on airplane mode.
And you might be able to make a shortcut to open the appropriate settings activity directly, instead of going through a few levels of menus to get there.
If you make your own build, you can presumably add the capability you really want, but that's likely not useful to anyone but yourself.
Related
We are developing a locked down "kiosk-style" Android app on a stock Samsung tablet, which is mounted in customer vehicles. We would like to be able to allow customers to edit their wifi settings, without giving them access to the rest of the Settings app (e.g. Launcher, accounts, etc)
We have been able to launch the Wifi Settings activity, but it allows the user to go into other areas.
I'm not sure whether it's possible to create a custom interface for connecting to wifi, but even if it were possible, this seems fragile and a lot of work for something quite simple.
Is there any way to solve this well?
I would create a device policy controller app that is provisioned on the device as a device owner using Android Enterprise (Android for Work) APIs.
https://developers.google.com/android/work/dpc/build-dpc
As a device owner, you can set your app in lock task mode which is generally used for kiosks.
https://developer.android.com/work/cosu.html
Then, you can set user restrictions:
addUserRestriction api
user restrictions list
The user restrictions don't cover everything in the settings app, but the coverage is pretty good.
Then I would provision it using NFC or QR code reader from the Google Setup Wizard welcome screen.
https://github.com/googlesamples/android-NfcProvisioning
You might want to also look at existing open source EMM/MDM implementations that already exist such as WSO2.
Other references:
How to enable task locking in Android 5.0 production devices
How to make sure there is only one app
I was also working on Kiosk Type applications and we have to give options for Change wifi and Display Settings So we have used these commands on Button click for Wifi And Display
Settings
btnWifiSetting.setOnClickListener {
startActivityForResult( Intent(android.provider.Settings.ACTION_WIFI_SETTINGS), 0);
}
And For Display Setting
btnDisplay.setOnClickListener {
startActivityForResult(Intent(android.provider.Settings.ACTION_DISPLAY_SETTINGS),0)
}
And you can also check the full list of Available Commands here
https://ourcodeworld.com/articles/read/318/how-to-open-android-settings-programmatically-with-java
try LineAgeOS
https://lineageos.org/
Your requirement needs to access OS System level, this way you have access and customize the WIFI settings before releasing the phone itself
can you try this way.
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
Tools_WiFi.setImageResource(R.drawable.tool_wifi_off);
} else {
wifiManager.setWifiEnabled(true);
Tools_WiFi.setImageResource(R.drawable.tool_wifi_on);
}
You can try this:
startActivityForResult(new Intent(Settings.ACTION_WIFI_SETTINGS), 0);
Hope it helps you.
I need to determine the country (iso3) the device is in even if the user's device has GPS turned off and does not allow apps to access it's location.
I also need to account for tablets that have no sim card and thus cannot use telephonyManager.
For this reason I don't believe I can use the location manager (also because of these reasons: LocationManager requestLocationUpdates doesn't work)
The approach I am thinking I will need is to make a simple HTTP request to a third party ip location api:
e.g.
http://www.ipinfodb.com/ip_location_api.php
or
https://freegeoip.net
Is this the best way to do it? What is the best open api to use?
Your approach of third party ip location api seems right to currently. May be This would help you
http://ip-api.com/docs/api:json
http://ip-api.com/json
You can use the TelephonyManager
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCode = tm.getNetworkCountryIso();
Update:
Since you cannot use telephony I would suggest trying this, as it get's the users input from when they setup the device.
String locale = context.getResources().getConfiguration().locale.getCountry();
Is it considered best practice or more acceptable or, for any other reason, preferable, to initialise WiFI on an Android device via a programmatic approach:
WifiManager oWiFIMgr = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
oWiFIMgr .setWifiEnabled(true);
vs. launching the WiFI settings activity?
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
I guess it depends on the purpose of your app.
If you are going to create a home screen widget like wifi toggle or something similar, the user would be pleased if just touching the widget turns On the wifi, but if its some app that just require the wifi access to do certain task, it would be better to open the wifi page allowing the user to take his own choice.
What really matters is you should design your app in such a way that once the purpose of wifi is done, it should be turned off again.
PS: No matter which choice you make in your app design the permissions of that app is going to be displayed during the installation.
So just keep in mind for the user friendliness of your app and its performance.
In Android Q (Android 10) you can't enable/disable wifi programmatically anymore. So you don't have a choice, you need to use Settings Panel to toggle wifi connectivity:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val panelIntent = Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY)
startActivityForResult(panelIntent, 0)
}
Always let user take those kind of decisions, enable WiFi, GPS .. stuff like that .. new Google maps app does that .. i think it's best ..
I am developing an application which does some downloading depends on whether the
user has enabled the option in Settings-> Wireless and network-> Mobile networks -> Use packet data.
I need to check the user has enabled this options.
Please help me to find out how can i get this settings.
For eg to check the roaming mode I use.,
import android.provider.Settings.Secure;
String android_id = Secure.getString(getContentResolver(),
Secure.DATA_ROAMING);
Thanks in advance
Deepu
works on 2.3:
ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
Method method = ConnectivityManager.class.getDeclaredMethod("getMobileDataEnabled");
method.setAccessible(true);
boolean res = (Boolean)method.invoke(manager);
Here I access private method ( boolean getMobileDataEnabled() ) by reflection, it is a not so good practice, but as we know, in Android it, in usual, the only way to implement something (even though CommonWare and other nerds think :)
In my app I want to change the phone type (GSM/CMDA).
getPhoneType() method in TelephonyManager
returns 1 (PHONE_TYPE_GSM)
or 2 (PHONE_TYPE_CDMA).
I can change this manually through phone
menu - Networks - Mobile Networks - Network Type ()
AUTO/GSM/CDMA.
Can I change this programmatically?
In Settings.Secure, you have NETWORK_PREFERENCE which is described as:
User preference for which network(s) should be used. Only the connectivity service should touch this.
This leads you to ConnectivityManager which looks like it is only for data connection, so all the above information really is useless, but good to be aware of.
And in TelephonyManager There is no set method, so the only thing that may work is if you look at internal and hidden methods.