I would like to ask a clarification about the meaning of the "Searching gps" notification. I have a simple app that tries to retrieve user position via FusedLocationProviderClient with this code:
val fusedLocationClient = LocationServices.getFusedLocationProviderClient(activity as Activity)
fusedLocationClient.lastLocation
.addOnSuccessListener { location: Location? ->
mMap.isMyLocationEnabled = true
// other trivial stuff here
}.addOnFailureListener {
// showing an error here
}
Even when last location is retrieved android keeps showing the "Searching gps" notification (Ricerca gps in the screenshot below). As far as you know, this means that app is still searching for gps updates (and so draining battery) or is a simple message to notify the user that the app is using the gps? Thanks for the clarification, my device is a Xiaomi Redmi 5 Plus (MiUI)
I'm not 100% sure I understand the question, but I'll take a stab here. I think one of two things is going on:
The notification is being explicitly shown by the MyFoody app and it's that app's responsibility to hide the notification once it no longer needs to be shown. You'd need to take care of clearing that notification in the listener's success and failure functions you've defined. Are your listeners being called? Do they clear the notification?
OR
It may be that Xiaomi has modified Android to show that notification on behalf of your app while it's retrieving location(s). If that's the case, then you'd need to figure out why this Xiaomi-modified Android version still thinks your app is trying to get a location. It could also just be a bug on Xiaomi's part, but I'd consider that as a last resort.
Related
I have written a foreground service in my app and I am doing some API operation every 5 minutes once. My app is mainly used for location tracking and it always needs location permission. If user disable the location for my app by any chance then I just want to create a local notification from my service. My app users mostly don't bring my app to foreground. So I want to check whether the location permission is enabled or not. If not then I just want to show a notification which tells the user that the app needs location permission. Now I just manually went to android settings and disabled the location permission for my app. I have two services running in my app. Suddenly both stopped working. I just want to know the reason why it stopped? Will it be stopped always until I enable the permission? What can I do to intimate my user to enable the permission? As my app always runs in background, I want to handle it in service. Please give your opinion to solve my issue.
NullPointerException: Attempt to read from field'LanguageInitBean$Data LanguageInitBean.data' on a null object reference
When I change the storage permission, I can't read the data stored in memory
Ask for help
public static class LanguageInitCache{
public static LanguageInitBean languageInitBean;
}
private void startToNext(String response) {
languageInitBean = GsonUtils.json2Bean(response, LanguageInitBean.class);
}
In my app I am using FusedLocationProviderClient to get user location every time he enters the app by mFusedLocationClient.getLastLocation().addOnCompleteListener().But sometimes result is null,I am using <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> in manifest.How can I get user location even if it not so correct?Because the logic of app depends on that location,I don't need to show it on map or smth like that,just get the location.Thx in advance
Don't use getLastLocation(). There is always a chance to have it return null if it doesn't have a location currently.. Use requestUpdates or requestSingleUpdates- when the callback for those is called the location is guaranteed to be non-null. getLastLocation() should only be used as an optimization to improve speed, it cannot be relied on.
Follow the following example and your app is guaranteed to work as you wish. I have recently used this code and it is working like a charm.
Only thing you should know is that for the location updates to actually work ( to get real latitude and longitude values) you should enable "google play services". There may be several ways to do this but perhaps the simplest of all is to open "settings" on your device and probably somewhere under "security" or "permissions" (depending on your android distribution) find "google play services" and give it the permission it needs.
https://github.com/googlesamples/android-play-location/tree/master/LocationUpdates
SO I've created geofence as below:
GeofenceModel modelExit = new GeofenceModel.Builder("id_oi_456")
.setTransition(Geofence.GEOFENCE_TRANSITION_DWELL)
.setExpiration(Geofence.NEVER_EXPIRE)
.setLatitude(40.414341)
.setLongitude(49.928548)
.setRadius(CLIENT_GEOFENCE_RADIUS)
.build();
SmartLocation.with(this).geofencing()
.add(modelExit)
.start(this);
I run this code once, it triggers when dwelling inside geofence (as expected). And then I delete the snippet and rerun the project. But geofence not triggered this time even if I have set NEVER_EXPIRE. So basically what I want to know is that where are the geonfences stored. In case they are stored outside app memory then why "deleting snippet" clears geofence?
I think it is working as intended. The project that goes to re-run will consider the app as fresh install. As stated in the documentation - Use Best Practices for Geofencing:
The app must re-register geofences if they're still needed after the following events, since the system cannot recover the geofences in the following cases:
The device is rebooted. The app should listen for the device's boot complete action, and then re- register the geofences required.
The app is uninstalled and re-installed.
The app's data is cleared.
Google Play services data is cleared.
The app has received a GEOFENCE_NOT_AVAILABLE alert. This typically happens after NLP (Android's Network Location Provider) is disabled.
Hope this helps.
I'm risking a few down-votes with this question, but today I've received a flood of user emails saying that every time my application starts, the GPS icon appears briefly in the notification bar - and I can replicate.
Pulling down the notification shade, I see 'Searching for GPS' momentarily appear - Managing to long-click it and select App-Info, it leads me to the System UI Application Settings.
In the logcat I see:
D/LocationManagerService(2358): request 448e9c20 gps Request[ACCURACY_FINE gps requested=+60m0s0ms fastest=+60m0s0ms] from com.google.android.gms(10021)
D/LocationManagerService(2358): provider request: gps ProviderRequest[ON interval=+60m0s0ms]
D/GpsLocationProvider(2358): setRequest ProviderRequest[ON interval=+60m0s0ms]
D/GpsLocationProvider(2358): startNavigating, singleShot is false
D/GpsLocationProvider_ex(2358): getSKAFEnable : false
D/GpsLocationProvider(2358): setting position_mode to MS_BASED
So, are any other developers having reports of this, the cause of which I assume is an update to Google Play Services?
I've changed nothing in my code (reports are coming in from users running a version 9 months old), so posting code that hasn't changed, seems a little pointless....
I thank you in advance....
EDIT - This seems to be something to do with using the Speech Recognition API as it is occurring in the Google Now application, every time you press the mic icon.
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)