Restrict users access to only certain Settings like Bluetooth, and GPS - android

Working on Kiosk app and trying restrict users access to just a few setting functions. In particular, GPS Settings. If Setting Dialog is brought up there is a little back/home button in at top of settings that allows users to click back to access all settings. I don't want them to be able to go back and set everything. Is there anyway to disable this or will I need to make custom interface to turn on/off each item under location services? The back button might be firing up another intent which could be caught or than again maybe its just calling finish or closing out dialog or fragment ...
Does anyone know what the little back button does under the hood? Any way to catch intent fire at this point?

Related

How to prevent user's from returning to the android home screen?

I'm working on a smartphone rental service.
When the user unlocks the app
1) I would like to launch xxx app, instead of the android home screen
2) Would like to prevent the user from returning to the dashboard of the app (when they press the device home button)
Possible solution I could think of
1) Open the app before passing it to the customer
2) Prevent the app from returning to android home screen when device home button is press by redirecting it to the app dashboard when the home button event is triggered.
Detect home button press in android
This code only detects the event but didn't prevent the user from going back to the home screen.
#Override
protected void onUserLeaveHint()
{
Log.d("onUserLeaveHint","Home button pressed");
super.onUserLeaveHint();
}
Hope it's not something I need to do on the OS level.
This actually something i've been working on for well over a year. It is not an easy task to accomplish nor is it going to be perfect, there is almost always a way out of the app without direct ROM access.
If you have access to all the hardware before the customer get's it you can use "Device Owner/Provisioning" which makes it much easier
https://source.android.com/devices/tech/admin/provision.html
Then with device owner you can use "Screen Pinning" without user prompting as well as disable specific apps etc.
https://developer.android.com/about/versions/android-5.0.html#ScreenPinning
Other than these, a recommended way is to
Request "App Usage Access" when starting the app (Settings>Security)
This will allow you to get the current "top" package, i.e. which app is running
Start a service which periodically checks the top app to check if it != the allowed app
If it is not your allowed app, then resume focus on your app
Of course there is other bits to consider, blocking of status bar (drawing an invisible view on top works well), prevention of access to system dialogues, requesting of "Device Admin" such that you can prevent uninstall of the main app without permission etc.

mark the particular setting from my App in android

I am getting problem in my app .where i need to mark the particular Settings I have used the following code:
startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
Its open the setting page but it does not mark the particular Entities.How could i get the automark option Could anybody help me out!!#Thanks
this is not possible, unless you have the rights and access the setting directly (not with an intent, but with the Settings class), and even though, I'm not sure you can.
What you can do is what google maps does. When your app starts, check if the gps is enabled, if it is not, display an alert notifying the user, with a button to quit the app, and a button to go to the settings screen. When the user comes back from Settings screen, test again.
If the action that you are trying to do was allowed then users would be very mad if some application would turn on their wireless connection or even worse the GPS sensor.
This change is available to change only by the user him self. So as mentioned the most you can do in case you need Internet connection or GPS sensor available is to present a user with the relevant message and fire an intent that will take them to the settings screen to change this setting them self.

Android App - navigating to phone settings and returning

My first question, (but long time lurker on StackOverflow) so please don't be too scathing.
I am creating an Android App that has the capability of using a web service to update an SQLite database. Of course, this can only happen if the phone has internet connectivity. I understand how to navigate to the phone settings from the App, but I would like to know if the phone is now connected to the internet upon the user returning to the App.
I have considered using the onStart() and onResume() methods, but is there any way to determine where the user 'came from'. A good example would be the Google Maps/Navigation App. If the user is in Google Maps and presses the Navigation icon, it opens the Navigation App/activity and if GPS is not on, a dialog box shows asking the user if he or she wants to be taken to the GPS settings. They can choose OK, turn on GPS and press the back button to return to the Navigation App. If GPS is now on, they can proceed, otherwise the App shows the dialog box again.
This is good, except the user is allowed to continue, in my case, if there is no internet connectivity. But if there is initially no connectivity, and the user goes away and turns it on, and comes back, then I want to call the method to call the service.
I only want the internet check to happen on opening the App, and upon returning from the phone settings. If I use the onStart() method, the check will happen every time the user opens the activity.
So my question is, how do I check that there is internet connectivity only in the onCreate() method AND when the user returns from the phone settings?
Thanks in advance.

Getting a result from a change in connection settings (wifi or 3G on) and closing the system settings

My activity opens the systems prefs when no internet connection is connected.
What is the best way to close the system prefs and go back to the activity as soon as the user activates wifi or 3g.
Is there a way to get a result using startActivityForRsults()?
Should I wake up the activity using a listener that detects when a connection is on?
Thank you or your thoughts
What is the best way to close the system prefs and go back to the activity as soon as the user activates wifi or 3g.
The user can press the BACK button to do this.
Is there a way to get a result using startActivityForRsults()?
AFAIK, none of the Settings activities are designed for startActivityForResult().
Should I wake up the activity using a listener that detects when a connection is on?
No.
Please do not break Android navigation. What you are proposing is the same as if the user clicked a link on your Web page to visit a different site, clicked on a checkbox on that third-party page, and you now expecting to have some way to force the user immediately back to your page. That's not how the Web works, and what you are proposing is not how Android works. Please allow the user to decide what to do next, whether that is press BACK to return to you, press HOME to go do something else, etc.
Yes, basically you need to register a BroadcastReceiver for android.net.conn.CONNECTIVITY_CHANGE and then check the intent that you receive to make sure that you now how network connectivity and if so then you can use startActivity to go on to what ever of your activites you want to display next.

Open System Settings from a Service

I am writing a service to collect location readings while my application is running in the foreground. In the LocationListener, I would like to use the onProviderDisabled() method to open a dialog telling the user that the location provider is disabled, and have a button on the dialog that will launch the system's location settings panel, allowing the user to enable the location provider if they choose. If this was an activity, I would launch the system settings using startActivityforResult(), but I can only use startActivity from a service.
My question is this: is there a way I can open the settings from a service, and have this new activity close and return to my application after the user changes a setting?
EDIT: What I'm trying to achieve is a Service running from the moment the application opens until it closes and collecting location readings, maintaining a best estimate of location for use in the application. If the LocationListener within the service has onProviderDisabled called, I want this to cause a dialog to open that will give the user the option to go to the System Settings and enable location providers (or cancel and carry on, although some of the application's features won't work without location). I agree that the perhaps the Service isn't the place to do the dialog/activity launch part as it is a background component with no UI, but I'm not sure where the code for this should go.
From the edit to your question and the comment to Sam's answer, I'd basically do a check in the Activity (or all Activities) of the app and launch the dialog and subsequent 'Settings' page from there (if the user chooses to go to Settings).
Basically, have the Service do what it needs to based on the current environment the main Activity encounters (provider disabled/enabled). If your Service will be running when there is no user front-end then have it compensate and reduce its 'duties' accordingly.
Also, in that scenario, Sam's idea of using a notification (which in turn could cause the Settings to be opened) is a good middle ground.
EDIT To explain a little further. Take something as simple as an email app. There are two aspects to this...
Firstly there's a UI - when the user opens their email app if 'the network' is disabled the user is told so with a dialog with the option to go to network settings to enable the network. Pressing BACK (from Settings) will return to the email app and it will attempt to download any new emails. If the user decides not to enable the network they can still view previously downloaded emails (similar to partial functionality in you situation).
Secondly there is a background service which periodically (every 15 mins, 30 mins, 1 hr etc) will attempt to download any new emails even if the UI is closed. If the network is disabled it will simply go to sleep (until next download time).
In theory if a user disables the network, the background email service 'could' provide a dialog or notification to say "You do realise I can't work now?"...this is kind of what you want to do BUT if the service has other things to do it can simply do those and ignore any network-related tasks. Next time the user fires up the Activity, they then get a dialog with the option to enable the network.
Does that make more sense?
Yes, Service has the ContextWrapper.startActivity() method which will open the desired Settings menu. The user will select what they would like to enable then touch back to return your Activity. Once back in your activity you can check LocationManager.isProviderEnabled(). Unfortunately a service cannot take an Activity result.
just curious. service may run even if the user is not seeing the screen, or even the screen may be turned off. is it a good idea, showing a dialog from the service.
anyway, since you know how to show an activity, in the onCreate fire the intent for the settings and finish it once you get to onActivityResult.
sure this is a simple hack.
EDIT: if you are not sure where it should go. the best i can think, and even seen in some apps is the notification area.

Categories

Resources