mark the particular setting from my App in android - 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.

Related

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

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?

Prompting User to Enable GPS

Correct me if I am wrong:
1) You cannot programatically turn GPS On/Off on all versions of Android. Maybe some previous versions, and some hacks, but not on all devices. It simply is not allowed.
This leaves only two options:
1) Use new Google Play Services to prompt user to change these settings.
One issue with this is what if you just want to allow user to turn on GPS,
but not WIFI? The resolver will give them options to turn on both. How
can you just turn on one but not the other?
2) Send user to the settings application by firing off an Intent.
Now with 1) User must have current google play services installed.
If not they can be prompted to install it via standard GPS dialog.
Ok, now for 2) Sending user to settings application. I have the following problem:
When I fire off this intent, they not only get to change the Location/GPS Settings but they can also hit the little back button within Settings app, and adjust all settings. Is there any way to prevent this? Anyway to bring up the Location/GPS Settings without the inner back button? Thanks.
You cannot programatically turn GPS On/Off on all versions of Android. Maybe some previous versions, and some hacks, but not on all devices. It simply is not allowed.
Correct, for obvious privacy reasons.
When I fire off this intent, they not only get to change the GPS Settings but they can also hit the little back button within Settings app, and adjust all settings. Is there any way to prevent this?
No.

Retrieving GPS coordinates when location services are not enabled

Assuming the device's "Use Wireless networks" and "Use GPS satellites" settings under Location is not enabled, is it possible to still retrieve the location coordinates.
Currently, the best is to redirect the user to the settings page is not enabled. I find this disruptive as needs to navigate away from the app.
If i am not mistaken, you can enable the settings programmatically (Am I correct?).
I don't need the exact coordinates, is it possible to get the cell tower ID without the settings enabled?
No. If the user doesn't want to give you his location, There is no way you can get his location.
This is a security measure and it exists for good reasons. If you try to subvert this, your app will be considered malicious.
Redirecting the user to the settings page is the best option.
Agreed - in earlier versions of android, you could programatically turn on the GPS - but more recent versions do not allow this to happen.
As Anup states - the common acceptable practice now is to redirect the user to the options page and allow the user to select the type and nature of GPS that the application is allowed to use.
Dont forget , you dont need to "leave the app" to get the user to turn on GPS, you can send them to the settings yourself:
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
This will then come back to your app where it left off - giveing the use a seamless experience, and one which they will be familiar with from other android apps.
Setting anything programatically without asking the user first is bad practice.
What you could do is, in case you can't get a location, ask the user to turn GPS on or tell him your app won't be able to work and will close.
switching on Location settings programmatically without the users consent is impossible let alone bad practice. You can prompt the user and direct him to switch on location settings or if you program tracks the progress of the device user, you can have the program send an alert of some sort telling them that the Location setting is off.
Deep dive into location has a set of best practices for Android's LocationManager. You do not need the GPS to be activated -- in many cases, the mobile network itself gives a pretty good approximation of the location without taking up extra battery.

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.

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