I am developing an Android Application and I need to make sure that the user is connected to the internet somehow. I can already check for WiFi, however, not everyone will be near a WiFi zone all the time, so I am thinking that Mobile Data is a valid alternative (of course assuming that the device is capable of having a SIM and all). So far, I can check if the user has enabled his or her mobile data as follows:
if(checkForMobileNetworkActive()){
//with mobile active
}
else{ // mobile not active
}
What I want to do is this: If the mobile network is NOT active, I will ask the user to turn it on. Very similar to what I have done in the past where I prompt the user to turn on their Bluetooth or the Location services. However, upon searching online, most answers pointed me to opening the WiFi settings via intent as such:
Intent i = new Intent(Settings.ACTION_WIFI_SETTINGS);
startActivity(i);
I have 2 issues with this solution:
- This opens a new activity and not an alert dialog-style prompt to turn the WiFi on.
- This turns on the WiFi and not the Mobile Data.
Has anyone tried to prompt the user to turn on their Mobile Data? As much as possible, I want it to look like the dialog box prompt and not an entire new activity (which is bad user experience in my opinion). I've looked on how to do it programmatically, however, what I stumbled upon no longer works for non-rooted device on Android Lollipop+ and I don't want to run the risk of the app no longer running when users upgrade the OS of their Android Devices.
Edit
I saw the link posted in the comment below, and I've tried this:
if(checkForMobileNetworkActive()){
}
else{
Intent i = new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
startActivity(i);
}
But it opens the Mobile Data/Data Roaming Settings as a new activity. While it works, it enables the user to check the checkbox for Mobile Data and pressing the back button goes back to my app, it is not a very smooth user experience.