how to enable GPS Automatically in android Oreo? - android

sorry for that because this question asked very time but i want to get user location in emergency condition so probably the user GPS possible not enable at this time also Internet.
so how i enable GPS at this time or other way to get location at this time without GPS and Internet ?
please provide code if possible? highly appreciated
android 8.1

I put my comment in answer field because of this restriction: 'You must have 50 reputation to comment'.
There is this 'Last Known Location' in the 'Fused Location Provider API'. Check them out.

Related

Android GPS - location tracking periodically

all
I'm working on my Android app which is required to track location of android periodically. The result will be sent to my server(maybe in php) whenever I click button "Get Location" on the server or sent periodically if I click button "Track Location", I have searched much for this topic but it seem to me that they are not helpful for me.
Can anyone give me a detail solution with full code?
Any help will be appreciated !
If you want to get track location right after click Get Location on the server, you have to implement an API to check if need to upload location, then create a service on client with calling this API, then upload when needed. And for Track location by period, you could also use service for it. For details, please try to search by yourself, there are many solutions for them already.
P/S: noone will give you a detail solution with full code, it's your job, not us!

How to know gps fix is available or not?

I am working on app. When user click on button he will get current location using GPS.
All is working fine but one problem.
Problem
There might be some location where gps will not work...like closed area...and gps can not find location...at that time it will return previously know location...Previously known location may be too older or wrong.
so at that time I want no location found instead of last location.
Is there any way to check if fix is available or not ?

Getting the message GEOFENCE_NOT_AVAILABLE when using Google Play Services API on Android

I downloaded the GeoDetection.zip file for trying out location based geofencing using the Google Play Services API that is available from the developer android website from the following link:
http://developer.android.com/training/location/geofencing.html
but when i tried to add geo fences using this app, i constantly get the error GEOFENCE_NOT_AVAILABLE
i tried to check what this error means, and i found that if location access is not available that is when i should get this message, but i checked the Location Services section on my phone and i saw that all the Location provides GPS/Wifi Location are all enabled. I am also connected to WIFI successfully. Not sure why i still get the message.
Any body else encounter this issue?..if so, do you have a fix that i could try?
Any other suggestions?.. i tried a lot of options to make sure it is capturing all the options, but there is isn't much debug information for me to proceed any further.
Thanks in advance
Are you requesting the FINE_LOCATION permission?
Remember on Android 6 and above you have to handle the permissions at run-time too.
The above error, GEOFENCE_NOT_AVAILABLE is an expected error code, to let you know that the location adapter is off and location (and geofence) will NOT be tracked anymore.
Once available again, your geofences will be active and you will get the desired callback.
Few Reasons why the triggers aren't happening :
Check if your expiry timestamp that you set in your geofence request, is still valid.
Did your device get restarted ? If yes, you need to re-register fences. (Refer documentation : Re-register geofences only when required documentation)
Is your location, set to High Accuracy mode in Device settings ?
When you re-register your fences, you should un-register them first and then only re-register.
Open Google maps and check if it's showing the right location.
Is Battery Optimisation on for your device ? This will delay geofence triggers
Is you app whitelisted for background operations (Happens in some Chinese OEM's)

Android : Turning GPS on Programmatically [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Enable GPS programatically like Tasker
All,
I seen most of the answers in this forum that we CANT turn on gps programmatic ally. I am wondering in some of the applications available in Android market, how do they do? I tried most of the things explained in this forum, it always gives a prompt to the user to enable the Location based services.
Any other thoughts?
Thanks,
Ramesh
Not sure what you mean by "turn it on". Do you mean enable or disable it? This thread discusses some ways to enable or disable it by exploiting bugs: How can I enable or disable the GPS programmatically on Android?. I wouldn't use this method though, since it won't work on devices where the bug has been fixed. Far better to forward the user to the settings app and let them enable gps.
Do you mean to turn it on or off to use it, assuming it's been enabled? You don't need to do that. Simply call LocationManager.requestLocationUpdates() with the right location provider, and the system will turn it on for you.
Have you looked here?
http://developer.android.com/guide/topics/location/strategies.html
What you can do is assert what type of location provider is enabled, check if it is GPS, if not add this to prompt the user to turn on GPS (be sure to run a long Toast to let the user know to enable GPS location and to hit the back button once enabled):
ComponentName intentComponent = new ComponentName("com.android.settings", "com.android.settings.LocationSettings");
Intent mainIntent = new Intent("android.intent.action.MAIN");
mainIntent.setComponent(intentComponent);
startActivity(mainIntent);

How to get user's location?

I want to get user's location in my app. So, I read documentations and know how to get it work. But, if user haven't set "Alloy apps to use internet/GPS to get location" in preferences, my app crashes.
The only way I found is to show dialog that location settings are not enabled and to go programmaticaly to location preferences.
But is there another way to solve this? I saw many apps (like yandex.maps) that do not request this settings being enabled.
well, your app should not install if the user doesn't agree to the terms of use, and allow the permissions requested.
still you should check to see that there's a way to look the information up when you want it.
in your code, before the actual test for user's location, you should probably call a function that checks for all the location manager listings, and return false if there's no way to determine this.
if the function returns false, you should prompt the user and do nothing. else, you should do what it is you're trying to do.
try reading vogella's tutorial about using location manager
Refer this two links below and you might get your answer easily.
How do I get the current GPS location programmatically in Android?
android - how to get current location latitude and longitude
Hope it will help you.

Categories

Resources