I just updated my Google dependencies to 12.0.1 and now I'm getting this error where I'm using FusedLocationProviderClient.
Any idea why is this happening? Looking into source code, I can see the the constructors are now hidden:
#Hide
public FusedLocationProviderClient(#NonNull Context var1) {
super(var1, LocationServices.API, (ApiOptions)null, new zzg());
}
#Hide
public FusedLocationProviderClient(#NonNull Activity var1) {
super(var1, LocationServices.API, (ApiOptions)null, new zzg());
}
But it doesn't make sense. Why? Google obviously wanted people to migrate to this new Location Provider. Why would they suddenly make it unavailable? I've checked out the docs and I can't find anything about this.
Luckily the code still compiles and location works. But still...why?
The documentation could have been clearer, but it seems the intention is for you to call LocationServices.getFusedLocationProviderClient(). See the API here.
Upgrade to version 15.0.0 released on the 12th it will clear the warning for you. I don't see anything in release notes or bug reports mentioning this, so it is probably just a bug introduced in 12.0.1.
Related
This is a problem that I've been stuck for weeks, but still, I can't solve it. My friend's google place picker worked, but not mine (even though we have the same code).
But once in 20-30 tries, it opens the UI lets me have a look at nearby places around my location (but that's a very very rare case).
I've done everything I possibly could.
1) I've enabled Google Places API for Android and generated my API key. I've also added my SHA-1 certificate fingerprint and package name.
2)I've imported everything related to google play services that I could in gradle.
implementation 'com.google.android.libraries.places:places-compat:1.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-vector-drawable:26.+'
implementation 'com.google.android.gms:play-services-places:16.0.0'
3)I've also given my API key inside of meta-data in my application tag in AndroidManifest.xml
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_place_api" />
</application>
4)I've copied the exact code that I got from Place-picker documentation site https://developers.google.com/places/android-sdk/placepicker
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(maps.this), PLACE_PICKER_REQUEST);
} catch (
GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (
GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
#Override
protected void onActivityResult ( int requestCode, int resultCode, Intent data){
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
5)I've even enabled billing for my project, where Google charged me Re 1.
This is very important for my project, so please someone help me. I beg of you.
Edit: I'm getting some kind of error in my logcat too:
Place Picker closing due to PLACES_API_ACCESS_NOT_CONFIGURED
the Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
2019-05-12 08:07:57.106 2818-3899/? E/Volley: [171] BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/placesandroid/v1/placePicker?key=AIzaSyCz-bC6nazJur-gHEgVoZMujFDyVvs2n9M
2019-05-12 08:07:57.110 2818-20254/? E/Places: Places API for Android does not seem to be enabled for your app. See https://developers.google.com/places/android/signup for more details.
2019-05-12 08:07:57.112 2818-20254/? E/AsyncOperation: serviceID=65, operation=PlacePickerQuota
EDIT#2: Is there any solution to this? Please answer me.
You seem not to have enabled place API, below is the link to the steps to get that done.
https://support.google.com/googleapi/answer/6158841?hl=en
if you check your logcat well enough, maybe by selecting the types of log you want to see, you can select Error instead of verbose, then you will see the error like below
E/Places: Places API for Android does not seem to be enabled for your app. See https://developers.google.com/places/android/signup for more details.
I believe the issue is related to the deprecated version of Places SDK for Android. You have the following statement in gradle
implementation 'com.google.android.gms:play-services-places:16.0.0'
This refers to the Google Play version of Places SDK, that was deprecared. In order to use new static library of Places SDK the gradle should use
implementation 'com.google.android.libraries.places:places:1.1.0'
Please double check all steps mentioned in the documentation of new library to be sure that you migrated to new version correctly:
https://developers.google.com/places/android-sdk/start
I hope this helps!
Getting a bit lost here: I need to update Mapbox's API from 4.x.x-beta to 5.x.x and a number of things, such as xml attributes' names, way of getting access token and location services has been changed. I dealt with the first two thanks to the documentation but cannot seem to make LocationServices methods work. Android Studio tells me that it cannot resolve methods such as getLocationServices() or getLastLocation(). Here's what my code looks like, that's what used to work with Mapbox 4.x:
package com.example.myapp.interactor;
import android.location.Location;
import com.mapbox.mapboxsdk.location.LocationServices;
import com.example.myapp.MyApp;
public class GpsInteractor {
private LocationServices locationServices;
public GpsInteractor() {
locationServices = LocationServices.getLocationServices(MyApp.applicationContext());
}
public Location lastKnownLocation() {
return locationServices.getLastLocation();
}
}
So, as per documentation here ("Getting Location Updates" section), I should copy LostLocationEngine class to my project. When I did so, it cannot access some of the fields from LocationRequest.java LOST API class, namely interval, fastestInterval and smallestDisplacement.
I found this question with really similar problem and tried to compile several combinations of Mapbox APIs, but no luck.
Am I missing something?
If you haven't modified the maps locationSource yet,
LocationEngine locationEngine = LocationSource.getLocationEngine(this) will return the default LOST location engine being used. Starting in 5.0.0 LocationEngine replaces the LocationServices class. For example, to get the last known user location, you can do this:
LocationEngine locationEngine = LocationSource.getLocationEngine(this)
locationEngine.getLastLocation();
You can read more on the LocationEngine in the new documentation here.
Google Analytics has been announced to become part of the rolling out Google Play Services 4.3, however it is not yet included in the Google Play Services packages list:
http://developer.android.com/reference/gms-packages.html
Any idea when it will become available, and will it be safe to be used straight away, or will it be better to wait for some time to make sure every user has Google Play Services 4.3 already installed?
I've noticed some other differences.
Tracker
To get a new Tracker, use the newTracker() method (accepts both a String value and an int value [for XML configuration]):
googleTracker = gaInstance.getTracker(GA_KEY); // OLD
googleTracker = gaInstance.newTracker(GA_KEY); // NEW
EasyTracker
EasyTracker has now disappeared, so we will have to use GoogleAnalytics.getInstance(this).reportActivityStart(this) as reported by Paito.
Setters
The googleTracker.set() method is no longer available. It has been replaced with more specialised methods, for example:
googleTracker.set(Fields.SCREEN_NAME, null); // OLD
googleTracker.setScreenName(null); // NEW
Event creation
The googleTracker.send() method has also seen some changes.
googleTracker.send(MapBuilder
.createEvent(category, action, label, value)
.build()); // OLD
googleTracker.send(new HitBuilders.EventBuilder()
.setCategory(category)
.setAction(action)
.setLabel(label)
.setValue(value)
.build()); // NEW
AppView
It now becomes
googleTracker.send(MapBuilder.createAppView().build()); // OLD
googleTracker.send(new HitBuilders.AppViewBuilder().build()); // NEW
AppViewBuilder
AppViewBuilder has now been deprecated, replaced by the new ScreenViewBuilder class. (thanks Hai Phong for the tip!)
For those who are running into (or have already dealt with) the Dalvik's 64K methods limit, there are now 3K methods that you will be able to get rid of in your application, thanks to this integration.
It's part of the package list now.
I think the basic functionality works something like this...
import com.google.android.gms.analytics.GoogleAnalytics;
#Override
protected void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
#Override
protected void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
As per conversation in order to use Easytracker replacement with
GoogleAnalytics.getInstance(this).reportActivityStart(this);
GoogleAnalytics.getInstance(this).reportActivityStop(this);
You need to add your config to AndroidManifest like
<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="#xml/analytics_global_config" />
I'm still having to get instance of Tracker to send Events, may be somebody else would have better luck at replacing
EasyTracker.getInstance(mContext).send(MapBuilder....)
The documentation for Google Analytics SDK v4 (now part of Google Play Services) has just been published!
https://developers.google.com/analytics/devguides/collection/android/v4/
I am using a simple conditional check on Build.Version.SDK_INT in the onCreate method of my application (code below) to prevent strict mode being enabled on any Android OS earlier than 2.3. Up until recently this had been working fine, but after a re-jig of my project, I receive the following error:
Could not find class 'android.os.StrictMode$ThreadPolicy$Builder', referenced from method com.myPackage.MyApp.onCreate
I have heard that the way class dependencies were evaluated and loaded changed from a static analysis of the class to a 'lazy loading' system in Android 2.0, but since I am using 2.2, I don't think this is at play. I suspect there is something elsewhere in my project structure that is causing this error, but I am at a loss as to what that might be.
Has anyone here had a similar experience and could maybe shed some light on this? Any help would be gratefully received.
Thanks in advance for your help!
Please see my code below for reference:
public class MyApp extends Application {
#Override
public void onCreate() {
// Set up strict mode
int buildInt = Build.VERSION.SDK_INT;
Log.d(LogTags.TRIGGER_CODE, String.format("Build is %d (%s)", buildInt, Build.VERSION.CODENAME));
if (buildInt >= 9) {
StrictMode.setThreadPolicy(new ThreadPolicy.Builder()
.detectCustomSlowCalls()
.detectNetwork()
.build());
StrictMode.setVmPolicy((new VmPolicy.Builder()
.detectAll()
.build()));
}
super.onCreate();
}
}
This turned out to be just a symptom of another problem elsewhere in code, far too specific to the project to be worth going into here...
Thanks for the thoughts on the root cause here, and sorry for the 'doh' moment :)
I'm trying to figure out how to track page views in real time without using the EasyTracker singleton.
I have the following code:
/**
* This how I create the tracker instance...
*/
private void createTracker() {
if (tracker != null)
return;
tracker = googleAnalytics.getTracker(googleAnalyticsSiteId);
tracker.setAnonymizeIp(trackingLevel.isAnonymous());
tracker.setAppInstallerId(configuration.getInstallationUUID());
tracker.setSampleRate(dispatchIntervalInSeconds);
trackUpgradedApp();
}
...
void someOtherMethod(Activity activity){
tracker.sendView((String) activity.getTitle());
// EasyTracker.getInstance().activityStart(cyborgScreen.getActivity());
}
While I uncomment the EasyTracker line, I can track the pages visited in realtime, but only after adding the analytics.xml to the project (obviously).
Once commenting the line, I do not receive the realtime information...
If following the code here, it should have done the trick.
Am I missing the obvious, or there is a bug?
Thanks,
Adam.
Well, after tones of playing around deleting, coping, changing things, I've found that this:
GAServiceManager.getInstance().setDispatchPeriod(dispatchIntervalInSeconds);
was missing, and that is why I could not see the realtime screen event without using the EasyTracker!
Hope this helps someone...
The answer is you call:
tracker.sendView((String) activity.getTitle());
but it can take time until you see it!