Android Question Google Maps tutorial problems

Aetius

Member
Licensed User
Hello, I'm new to android world and to B4A enviroment.
I need to practice with google maps, so I read this topic https://www.b4x.com/android/forum/threads/google-maps.63930/#post-404386.

i follow this step:
1 Read article and download last release of GoogleMaps library
2 Put GoogleMaps.jar and GoogleMaps.xml into AdditionalLibrary Folder.
3 Copy And paste code into a sample application.
4 Disable MyLocationEnabled into designer and enable it by code into MapFragment1_Ready event
5 With SdkManager I installed Google play service maps
6 Install Android SDK 27
7 Create a new device emulator for sdk 27

When I run my project function MapFragment1.IsGooglePlayServicesAvailable reteunr always false and screen show ToastMessage and message you can see in Output.png.

Plase pay attention in source code I mask my Google APIKey, please change it with valid Key....

there are two days I try to run it, I do not know what else to try.

I hope someone can help me.
thanks for reading up here and thanks to anyone who will help me
 

Attachments

  • Output.png
    Output.png
    15.3 KB · Views: 366
  • Play-Services.png
    Play-Services.png
    57.7 KB · Views: 348
  • Emulator.png
    Emulator.png
    33 KB · Views: 356
  • GoogleTest.zip
    3.9 KB · Views: 369

Aetius

Member
Licensed User
Thank you Donmanfred for you simple answer, with my surprise on a real device MapFragment1.IsGooglePlayServicesAvailable return true
Does this mean that emulator can't be used to debug apps that use Google Api?
I was hoping I could test the app on different versions of andorid just using the emulator.

Now I have another problem, I get a blank screen.
this is my Log there is a strange error invalid APIKey.

--------- beginning of /dev/log/system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.RuntimeException: Unable to pause activity {com.technosoft.O2Finder/com.technosoft.O2Finder.main}: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3196)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3151)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3129)
at android.app.ActivityThread.access$900(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
at com.google.maps.api.android.lib6.drd.q.b:)com.google.android.gms.dynamite_dynamitemodulesb@12685003@12.6.85 (000306-197041431):40)
at com.google.maps.api.android.lib6.auth.e.a:)com.google.android.gms.dynamite_dynamitemodulesb@12685003@12.6.85 (000306-197041431):11)
at com.google.maps.api.android.lib6.impl.e.a:)com.google.android.gms.dynamite_dynamitemodulesb@12685003@12.6.85 (000306-197041431):4)
at com.google.android.gms.maps.internal.b.a:)com.google.android.gms.dynamite_dynamitemodulesb@12685003@12.6.85 (000306-197041431):24)
at com.google.android.gms.maps.internal.CreatorImpl.a:)com.google.android.gms.dynamite_dynamitemodulesb@12685003@12.6.85 (000306-197041431):69)
at com.google.android.gms.maps.internal.CreatorImpl.newMapFragmentDelegate:)com.google.android.gms.dynamite_dynamitemodulesb@12685003@12.6.85 (000306-197041431):32)
at com.google.android.gms.maps.internal.i.onTransact:)com.google.android.gms.dynamite_dynamitemodulesb@12685003@12.6.85 (000306-197041431):31)
at android.os.Binder.transact(Binder.java:347)
at com.google.android.gms.internal.maps.zza.transactAndReadException(Unknown Source)
at com.google.android.gms.maps.internal.zzf.zzc(Unknown Source)
at com.google.android.gms.maps.MapFragment$zzb.zzc(Unknown Source)
at com.google.android.gms.maps.MapFragment$zzb.setActivity(Unknown Source)
at com.google.android.gms.maps.MapFragment$zzb.zza(Unknown Source)
at com.google.android.gms.maps.MapFragment.onAttach(Unknown Source)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:862)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1075)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
at android.app.FragmentManagerImpl.dispatchPause(FragmentManager.java:1874)
at android.app.Activity.performPause(Activity.java:5472)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1250)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3182)
... 12 more
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **

The Api Key I put in Manifest is the same I get from google Play developer platform, "AIzaSyC.......".

Where I'm Wrong?
 
Upvote 0

Aetius

Member
Licensed User
Hi Erel,
I apologize for writing in wrong forum.
I have a question about correct policy of forum.
When I have a question about an old thread, more than 1 year as now, I must opennew therad in question forum or continue previous thread?

Is there a post or a file with foums policy?

Please can you remove my post from Tutorials&Example?
 
Upvote 0

Aetius

Member
Licensed User
Hello everyone,
and after tried tired and tried again I got result.
Google maps demo works without errors.

I made two errors in my code:

1 during the tests, I deleted this line of code
gmap = MapFragment1.GetMap
for this reason I obtained null pointer exception

2 I put manifest metadata into wrong tag

I had the greatest difficulties in modifying the manifest, due to the constant references to the version of B4A used in the first post of tutorial.

This is the correct content of my Manifest file, to prevent others from making my own mistakes.
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136

AddManifestText
(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="27" />
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
)
AddApplicationText(
<meta-data android:name="com.google.android.geo.API_KEY" android:value="PUT_HERE_YOUR_GOOGLE_API_KEY" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)

'End of default text.

I have a quaestion again about Development process of this application.
I debug application on a real device and I found a strange behaviour, I get Log messages of exception, like Google API Key not valid but the App works correctly.
To stop this messages I remove application from device and reinstall it again, without any changes, so it works good without error notifications.
I would like to know if the same thing happened to someone else.
 
Upvote 0

Aetius

Member
Licensed User
Hi Erel,
As I write in first post I start reading your tutorial, I was very confused about the items to add to the manifest, so I tried and tried again until the demo worked.
I publish this manifest with hope that it could be useful to other newbie as me.
With this manifest the application works correctly.

The application does not work on the emulator because it does not find Google-Play services, it has been successfully tested on an old samsung S3 phone with Android 4.3

I started adding all Firebase Lines to manifest, but I receive an error about .Json file missed.
I don't Know where download google-services.json, I noticed "No need to add anything related to Firebase." so I remove all Firebase lines and it works.

Please can you tell me what's wrong in my manifest?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
As I write in first post I start reading your tutorial, I was very confused about the items to add to the manifest
1.
- Add this snippet to the manifest editor (replace the value with your key):
B4X:
AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="AIzaSxxxxxxxxx "/>
)
Add Google Play Services Base snippet from this link to the manifest editor.
No need to add anything related to Firebase.
2.
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)

This is all that needs to be added.

The emulator issue is not related. You should test it on a real device.
 
Upvote 0

Aetius

Member
Licensed User
I find only this difference
B4X:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

I delete this line and it works again, so I realize this line is not required.

can you confirm permission declaration are needed to put application in Google market?

B4X:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Thank you for your support.
 
Upvote 0
Top