Android Tutorial FusedLocationProvider + Resolution Dialog

** This is the only option to enable location services from inside your app. **

Example was updated and is based on B4XPages.
Don't miss:

1. ShowResolutionDialog sub that is added to Main. It needs to be added to the activity that hosts B4XPages.
2. #AdditionalJars in Main.
3. Manifest editor addition.


i_view64_fHopQqm7Zd.png
 

Attachments

  • Project.zip
    14.6 KB · Views: 1,374
Last edited:

Roberto P.

Well-Known Member
Licensed User
Longtime User
wich is the difference widht GPS module? and why we can use this library?
thank
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
FusedLocationProvider uses all kinds of location services to get the location including GPS, wifi data and others. It is more powerful and offer more options.
okay, so do you recommend replacing the GPS management with Fused Location?
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
actually I have a management with GPS module that very often - especially in the office - has functioning problems because it cannot intercept the coordinates.
if you tell me that it is a more performing service, I value the replacement.
 

imbault

Well-Known Member
Licensed User
Longtime User
That's pretty fast indeed, but how to stop it from Main Activity in your example, and start it again, in order to have several activities that use it

Thanks

Patrick
 

SMOOTSARA

Active Member
Licensed User
Longtime User



hi ?
How can I fix this problem?



B4X:
Logger connected to:  asus ASUS_X00LD
--------- beginning of main
*** Service (starter) Create ***
starter_service_create (java line: 237)
java.lang.IncompatibleClassChangeError: Found class com.google.android.gms.common.api.GoogleApiClient, but interface was expected (declaration of 'com.google.android.gms.common.api.GoogleApiClient' appears in /data/app/b4a.example-WJq-n16LbXDdO964anOKDQ==/base.apk)
    at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProviderWrapper.Connect(FusedLocationProviderWrapper.java:147)
    at b4a.example.starter._service_create(starter.java:237)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at b4a.example.starter.onCreate(starter.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3359)
    at android.app.ActivityThread.-wrap4(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:169)
    at android.app.ActivityThread.main(ActivityThread.java:6521)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Copying updated assets files (1)
*** Service (starter) Create ***
java.lang.IncompatibleClassChangeError: Found class com.google.android.gms.common.api.GoogleApiClient, but interface was expected (declaration of 'com.google.android.gms.common.api.GoogleApiClient' appears in /data/app/b4a.example-AnsVmiIpBBkkPNYLEWFogQ==/base.apk)
    at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProviderWrapper.Connect(FusedLocationProviderWrapper.java:147)
    at b4a.example.starter._service_create(starter.java:292)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at b4a.example.starter.onCreate(starter.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3359)
    at android.app.ActivityThread.-wrap4(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:169)
    at android.app.ActivityThread.main(ActivityThread.java:6521)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
--------- beginning of crash
java.lang.RuntimeException: Unable to create service b4a.example.starter: java.lang.RuntimeException: java.lang.IncompatibleClassChangeError: Found class com.google.android.gms.common.api.GoogleApiClient, but interface was expected (declaration of 'com.google.android.gms.common.api.GoogleApiClient' appears in /data/app/b4a.example-AnsVmiIpBBkkPNYLEWFogQ==/base.apk)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3369)
    at android.app.ActivityThread.-wrap4(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:169)
    at android.app.ActivityThread.main(ActivityThread.java:6521)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.RuntimeException: java.lang.IncompatibleClassChangeError: Found class com.google.android.gms.common.api.GoogleApiClient, but interface was expected (declaration of 'com.google.android.gms.common.api.GoogleApiClient' appears in /data/app/b4a.example-AnsVmiIpBBkkPNYLEWFogQ==/base.apk)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at b4a.example.starter.onCreate(starter.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3359)
    ... 8 more
Caused by: java.lang.IncompatibleClassChangeError: Found class com.google.android.gms.common.api.GoogleApiClient, but interface was expected (declaration of 'com.google.android.gms.common.api.GoogleApiClient' appears in /data/app/b4a.example-AnsVmiIpBBkkPNYLEWFogQ==/base.apk)
    at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProviderWrapper.Connect(FusedLocationProviderWrapper.java:147)
    at b4a.example.starter._service_create(starter.java:292)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    ... 11 more
*** Service (starter) Create ***
java.lang.IncompatibleClassChangeError: Found class com.google.android.gms.common.api.GoogleApiClient, but interface was expected (declaration of 'com.google.android.gms.common.api.GoogleApiClient' appears in /data/app/b4a.example-AnsVmiIpBBkkPNYLEWFogQ==/base.apk)
    at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProviderWrapper.Connect(FusedLocationProviderWrapper.java:147)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at b4a.example.starter.onCreate(starter.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3359)
    at android.app.ActivityThread.-wrap4(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:169)
    at android.app.ActivityThread.main(ActivityThread.java:6521)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
java.lang.RuntimeException: Unable to create service b4a.example.starter: java.lang.RuntimeException: java.lang.IncompatibleClassChangeError: Found class com.google.android.gms.common.api.GoogleApiClient, but interface was expected (declaration of 'com.google.android.gms.common.api.GoogleApiClient' appears in /data/app/b4a.example-AnsVmiIpBBkkPNYLEWFogQ==/base.apk)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3369)
    at android.app.ActivityThread.-wrap4(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:169)
    at android.app.ActivityThread.main(ActivityThread.java:6521)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.RuntimeException: java.lang.IncompatibleClassChangeError: Found class com.google.android.gms.common.api.GoogleApiClient, but interface was expected (declaration of 'com.google.android.gms.common.api.GoogleApiClient' appears in /data/app/b4a.example-AnsVmiIpBBkkPNYLEWFogQ==/base.apk)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at b4a.example.starter.onCreate(starter.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3359)
    ... 8 more
Caused by: java.lang.IncompatibleClassChangeError: Found class com.google.android.gms.common.api.GoogleApiClient, but interface was expected (declaration of 'com.google.android.gms.common.api.GoogleApiClient' appears in /data/app/b4a.example-AnsVmiIpBBkkPNYLEWFogQ==/base.apk)
    at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProviderWrapper.Connect(FusedLocationProviderWrapper.java:147)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    ... 11 more
*** Service (starter) Create ***
 

josejad

Expert
Licensed User
Longtime User
Maybe it would be a good idea let the original example too, for people not using B4XPages yet?
 

Justcooldev

Member
Licensed User
I am trying to use project.zip (FLP2) on several phones:

API 29: working
API 22 & 25: does not work (no results)

Do you know how I can fix the problem?

Thank you for your help.
 

Justcooldev

Member
Licensed User
Hi,

Thank you Erel for your help.

Here's what's going on with FusedLocationProvider (version 1.31) :

1) When launching the application :

LOGS :
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Connected to location provider

ON THE PHONE :
MainPage
Start
Location :N/A
State: N/A

2) when click start button :

LOGS :
State: Location enabled - waiting for updates

ON THE PHONE:
MainPage
Start
Location: N/A
State: Location enabled - waiting for updates


3) when click again on start button

LOGS and ON THE PHONE : the same as in point 2

Thank you
 
Top