New Google Play services stuff like low power location

Discussion in 'Android Questions' started by bluedude, May 28, 2013.

  1. marcel

    marcel Active Member Licensed User

    Hi, Yes I know but when i do this I get a lot of errors of othe resource files?

    Code:
    Generating R file.  Error
    res\values\ahqa_styles.xml:
    3: error: Resource does not already exist in overlay at 'Animations'; use <add-resource> to add.
    res\values\ahqa_styles.xml:6: error: Resource does not already exist in overlay at 'Animations.PopDownMenu'; use <add-resource> to add.
    res\values\ahqa_styles.xml:8: error: Resource does not already exist in overlay at 'Animations.PopDownMenu.Left'; use <add-resource> to add.
    res\values\ahqa_styles.xml:9: error: Resource at Animations.PopDownMenu.Left appears in overlay but not in the base package; use <add-resource> to add.
    res\values\ahqa_styles.xml:
    10: error: Resource at Animations.PopDownMenu.Left appears in overlay but not in the base package; use <add-resource> to add.
    res\values\ahqa_styles.xml:
    13: error: Resource does not already exist in overlay at 'Animations.PopDownMenu.Right'; use <add-resource> to add.
    res\values\ahqa_styles.xml:14: error: Resource at Animations.PopDownMenu.Right appears in overlay but not in the base package; use <add-resource> to add.
    res\values\ahqa_styles.xml:
    15: error: Resource at Animations.PopDownMenu.Right appears in overlay but not in the base package; use <add-resource> to add.
    res\values\ahqa_styles.xml:
    18: error: Resource does not already exist in overlay at 'Animations.PopDownMenu.Center'; use <add-resource> to add.
    res\values\ahqa_styles.xml:19: error: Resource at Animations.PopDownMenu.Center appears in overlay but not in the base package; use <add-resource> to add.
    res\values\ahqa_styles.xml:
    20: error: Resource at Animations.PopDownMenu.Center appears in overlay but not in the base package; use <add-resource> to add.
    ..
     
  2. corwin42

    corwin42 Expert Licensed User

    This is a known issue with B4A 3.20 and should be fixed in the next version. See here.

    You would get the same error if the function is added to the library. Workaround for now (since it is fixed in B4A) is to move your additional ressources to the #AdditionalRes folder.
     
  3. marcel

    marcel Active Member Licensed User

    Hi,

    Ok. That's a kind of hassle because I mess up all my resource files. Ok. I will wait for the next B4A version.
     
  4. marcel

    marcel Active Member Licensed User

    Hi,

    I did get some wierd behaviours in my app. So I used the example of Martin again. (attached).

    On the device settigns I have in location Services:

    Use wireless networks : ON
    Use GPS satellites : OFF

    I will start the program "Location Client" and press the button "Tracking OFF". New locations updates are comming and everything seems to works fine.

    Now I switch off in the settings Location Services:
    Use wireless networks: OFF
    rest is the same

    THe programs stops updating locations (which seems locical). Now I go to the settings Location Services:
    Use wireless networks: ON
    rest the same

    I expect that the service sees the change and start updateing again. But it won't infact when I press the button "Tracking ON" and stat again "Tracking OFF". this will not help it all. Also killing the program and start again won't help. I need to reboot my device and than it works again????

    Another thing I expected when I press "Tracking ON" (which destroy the service) is that the procedure:

    Code:
    Sub LocationClient1_Disconnected
        
    Log("LocationClient1_Disconnected")
        
    StopService("")
    End Sub
    will be called. This is not the case. So when I call again the service and this will be started the LocationClient is still connected. Even though the
    LocationClient1.Disconnect is called when the Service will be destoryed.

    Could some of you check this on your device? I used an Samsung Android S2 4.1.2.

    Is there a failure in the demo code or library? Or is it my device that behaives wierd?

    Thanks

    Marcel
     

    Attached Files:

  5. marcel

    marcel Active Member Licensed User

    When I changed the code in the service destroy, the closing went ok and the next time I start it is disconnected:

    Code:
    Sub Service_Destroy
          
    Log("Destroy the location Service")
        
    If LocationClient1.IsConnected Then
            LocationClient1.RemoveLocationUpdates(LocationListener1)
            LocationClient1.Disconnect
        
    End If
    End Sub
    Don't ask me why :)

    I am not sure if this is machine related or not.
     
  6. fricentric

    fricentric Member Licensed User

    I get the below error:
    Code:
    LogCat connected to: emulator-5554
    ** 
    Activity (main) Create, isFirst = true **


    ** 
    Activity (main) Resume **


    ** 
    Service (locationtracker) Create **


    java.lang.NoClassDefFoundError: com.google.android.gms.R$
    string


       at com.google.android.gms.internal.ib.<init>(Unknown Source)
       at com.google.android.gms.internal.hi.<init>(Unknown Source)
       at com.google.android.gms.location.LocationClient.<init>(Unknown Source)
       at uk.co.martinpearman.b4a.android.gms.location.LocationClient.Initialize(LocationClient.java:
    127)
       at uk.co.martinpearman.b4a.locationapidemo.locationtracker._service_create(locationtracker.java:
    174)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:
    521)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    174)
       at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    158)
       at uk.co.martinpearman.b4a.locationapidemo.locationtracker.onCreate(locationtracker.java:
    45)
       at android.app.ActivityThread.handleCreateService(ActivityThread.java:
    2959)
       at android.app.ActivityThread.access$
    3300(ActivityThread.java:125)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:
    2087)


       at android.os.Handler.dispatchMessage(Handler.java:
    99)
       at android.os.Looper.loop(Looper.java:
    123)
       at android.app.ActivityThread.main(ActivityThread.java:
    4627)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:
    521)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    868)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    626)
       at dalvik.system.NativeStart.main(Native Method)
    ** 
    Service (locationtracker) Create **


    java.lang.NoClassDefFoundError: com.google.android.gms.R$
    string


       at com.google.android.gms.internal.ib.<init>(Unknown Source)
       at com.google.android.gms.internal.hi.<init>(Unknown Source)
       at com.google.android.gms.location.LocationClient.<init>(Unknown Source)
       at uk.co.martinpearman.b4a.android.gms.location.LocationClient.Initialize(LocationClient.java:
    127)
       at uk.co.martinpearman.b4a.locationapidemo.locationtracker._service_create(locationtracker.java:
    174)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:
    521)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    174)
       at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    158)
       at uk.co.martinpearman.b4a.locationapidemo.locationtracker.onCreate(locationtracker.java:
    45)
       at android.app.ActivityThread.handleCreateService(ActivityThread.java:
    2959)
       at android.app.ActivityThread.access$
    3300(ActivityThread.java:125)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:
    2087)


       at android.os.Handler.dispatchMessage(Handler.java:
    99)
       at android.os.Looper.loop(Looper.java:
    123)
       at android.app.ActivityThread.main(ActivityThread.java:
    4627)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:
    521)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    868)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    626)
       at dalvik.system.NativeStart.main(Native Method)
     
  7. warwound

    warwound Expert Licensed User

    You need to include the Google Play Services library resources in your b4a project.
    That wasn't originally required when this thread was started but is now required.

    Look at the Google Maps tutorial thread.
    You need to follow step #6 and add an AdditionalRes attribute to your project.

    Martin.
     
  8. fricentric

    fricentric Member Licensed User

    i followed step 6 and now i get the below error
    Code:
    ** Activity (main) Create, isFirst = true **


    ** 
    Activity (main) Resume **


    ** 
    Service (locationtracker) Create **


    ** 
    Service (locationtracker) Start **


    java.lang.IllegalStateException: The meta-data tag 
    in your app's AndroidManifest.xml does not have the right value.  Expected 4323000 but found 0.  You must have the following declaration within the <application> element:  <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
       at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
       at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
       at uk.co.martinpearman.b4a.android.gms.location.GooglePlayServicesHelper.IsGooglePlayServicesAvailable(GooglePlayServicesHelper.java:
    27)
       at uk.co.martinpearman.b4a.locationapidemo.locationtracker._service_start(locationtracker.java:
    204)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:
    521)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    174)
       at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    158)
       at uk.co.martinpearman.b4a.locationapidemo.locationtracker.handleStart(locationtracker.java:
    68)
       at uk.co.martinpearman.b4a.locationapidemo.locationtracker.onStartCommand(locationtracker.java:
    53)
       at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:
    3053)
       at android.app.ActivityThread.access$
    3600(ActivityThread.java:125)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:
    2096)
       at android.os.Handler.dispatchMessage(Handler.java:
    99)
       at android.os.Looper.loop(Looper.java:
    123)
       at android.app.ActivityThread.main(ActivityThread.java:
    4627)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:
    521)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    868)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    626)
       at dalvik.system.NativeStart.main(Native Method)
    java.lang.RuntimeException: Unable 
    to start service uk.co.martinpearman.b4a.locationapidemo.locationtracker@44fb0c40 with Intent { cmp=uk.co.martinpearman.b4a.locationapidemo/.locationtracker }: java.lang.RuntimeException: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4323000 but found 0.  You must have the following declaration within the <application> element:  <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
       at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3063)
       at android.app.ActivityThread.access$3600(ActivityThread.java:125)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2096)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:123)
       at android.app.ActivityThread.main(ActivityThread.java:4627)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:521)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
       at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4323000 but found 0.  You must have the following declaration within the <application> element:  <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:200)
       at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
       at uk.co.martinpearman.b4a.locationapidemo.locationtracker.handleStart(locationtracker.java:68)
       at uk.co.martinpearman.b4a.locationapidemo.locationtracker.onStartCommand(locationtracker.java:53)
       at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3053)
       ... 10 more
    Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4323000 but found 0.  You must have the following declaration within the <application> element:  <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
       at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
       at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
       at uk.co.martinpearman.b4a.android.gms.location.GooglePlayServicesHelper.IsGooglePlayServicesAvailable(GooglePlayServicesHelper.java:27)
       at uk.co.martinpearman.b4a.locationapidemo.locationtracker._service_start(locationtracker.java:204)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:521)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)


       ... 14 more
     
  9. warwound

    warwound Expert Licensed User

    :) Yet another change that you have to make.

    Open the manifest editor and add this entry:

    Code:
    AddApplicationText(<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />)
    Martin.
     
  10. fricentric

    fricentric Member Licensed User

    Thank You Martin.
    That got the app working.
     
    warwound likes this.
  11. Ratna Fang

    Ratna Fang Member Licensed User

    hi martin :)
    i tried to add service and make is simpler like this
    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim GooglePlayServicesHelper1 As GooglePlayServicesHelper
        
    Dim LocationClient1 As LocationClient
        
    Dim LocationListener1 As LocationListener
        
    Dim LocationStatusCodes1 As LocationStatusCodes
       
        
    Dim GoogleLat As Double, GoogleLong As Double
    End Sub

    Sub Service_Create
        LocationClient1.Initialize(
    "LocationClient1")
    End Sub

    Sub Service_Start (StartingIntent As Intent)
        
    If LocationClient1.IsConnected Then
            
    CallSub2(Main, "UpdateStatus""Waiting for location updates")
        
    Else
            
    Dim ServiceStatus As Int=GooglePlayServicesHelper1.IsGooglePlayServicesAvailable
            
    Select ServiceStatus
                
    Case GooglePlayServicesHelper1.SUCCESS
                    
    Log("GooglePlayServicesHelper IsGooglePlayServicesAvailable service available")
                    
    CallSub2(Main, "UpdateStatus""LocationClient connection")
                    LocationClient1.Connect
                
    Case Else
                    
    Log("GooglePlayServicesHelper IsGooglePlayServicesAvailable returned: "&ServiceStatus)
                    
    CallSub2(Main, "UpdateStatus""Google Play Services unavailable")
                    
    StopService("")
            
    End Select
        
    End If
       
    End Sub

    Sub Service_Destroy
        
    '    i don't think we actually need to remove the listener and geofences
        '    i think calling Disconnect is all we need to do
        '    need to check and test...
       
        
    If LocationListener1.IsInitialized Then
            LocationClient1.RemoveLocationUpdates(LocationListener1)
        
    End If
       
        
    If LocationClient1.IsConnected Then
            LocationClient1.Disconnect
        
    End If
    End Sub

    Sub LocationClient1_Connected
        
    'not sure if this is a good idea, to pass the last known location to the LocationChanged Sub
        'pokoknya hajar aja ambil last know location
        Dim LastLocation As Location=LocationClient1.GetLastLocation
        
    If LastLocation.IsInitialized Then
            
    'Log("Manually calling LocationListener1_LocationChanged")
            'dipanggil manual ben remuk
            LocationListener1_LocationChanged(LastLocation)
        
    End If
       
    End Sub

    '    ** the GPS library must be enabled to work with Location objects **
    Sub LocationListener1_LocationChanged(Location1 As Location)
        
    'Main.Locations.Add(Location1)
        GoogleLat=Location1.Latitude
        GoogleLong=Location1.Longitude
    End Sub
    but when i compile the project (b4a 3.8), i got this:
    Code:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/cast/Cast$CastApi$a$
    9;
        at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:
    123)
        at com.android.dx.dex.file.DexFile.add(DexFile.java:
    163)
        at com.android.dx.command.dexer.Main.processClass(Main.java:
    490)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:
    459)
        at com.android.dx.command.dexer.Main.access$
    400(Main.java:67)
        at com.android.dx.command.dexer.Main$
    1.processFileBytes(Main.java:398)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:
    245)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:
    131)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:
    109)
        at com.android.dx.command.dexer.Main.processOne(Main.java:
    422)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:
    333)
        at com.android.dx.command.dexer.Main.run(Main.java:
    209)
        at com.android.dx.command.dexer.Main.main(Main.java:
    174)
        at com.android.dx.command.Main.main(Main.java:
    91)
    1 error; aborting
        Optimized dexer failed. Switching 
    to Standard dexer.
    i use this location api to retrieve lat lng without gps like when i used locationmanager library.
    i also edit, remove <depends on> in the xml file and compile again. and it's still failed.

    just have no idea. if i remove the location api library (and also remove the service from this project), i can compile successfully.
    this project is using google map library and the manifest is correct.
     
  12. warwound

    warwound Expert Licensed User

  13. Ratna Fang

    Ratna Fang Member Licensed User

    thanks for fast reply.
    yes, i'm using google map, admob v.2, and location api.
    all those libraries are in separate library folder, not in b4a default library folder.

    is there any problem between those libraries? i need to remove one by one to check which one is not compatible.

    *what is a chromecast?
     
  14. warwound

    warwound Expert Licensed User

    Cromecast, streams media from the internet to a HDMI port.

    You'd obviously not using a Chromecast but have a compile error that the Cast API is being included in your library more than once.
    The Cast API is part of the Google Play Services library so look in your code to find where and how you're including the google-play-services.jar and it's associated resource files.
    I'd guess the google-play-services.jar is being included more than once - it might even be that an old version of google-play-services.jar is being included as well as a newer version.
    Are you using the AdditionalRes project attribute to include the Google Play Services resources?

    Can you export your project as a zip file and upload it and i'll take a look?

    Martin.
     
  15. warwound

    warwound Expert Licensed User

    One more thought...

    Have you copied the Google Play Services 'res' folder to your project's Objects\res folder and also used an AdditionalRes project attribute to include them a second time?

    Martin.
     
  16. Ratna Fang

    Ratna Fang Member Licensed User

    the zip is more than 10 mb :(
    i'll create a new project and loads all 3 libs together.
     
  17. Ratna Fang

    Ratna Fang Member Licensed User

    yes. i always copy the latest google play jar and also point it out in the main
    Code:
    #AdditionalRes: E:\androidsdk\adt-bundle-windows-x86_64\adt-bundle-windows\sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
    my latest integer version is 4242000
     
  18. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    Hi All.

    I tried to use the library, but looks the GooglePlayServicesHelper library is missing.

    Can anybody help me?
     
  19. Ratna Fang

    Ratna Fang Member Licensed User

    hi martin...
    got the solution :)
    remove google map lib, copy new google play jar, add google map again.
    compile then it works.

    thanks alot :)
     
  20. brelto85

    brelto85 Active Member Licensed User

    i've 3.82 and i've installed the last android sdk updates (20)
    I've the following error when i click to Start button:

    java.lang.IllegalStateException: A required meta-data tag in your app's AndroidManifest.xml does not exist. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

    It works if i add these:

    #AdditionalRes: C:\Program Files (x86)\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

    and into manifest:

    AddApplicationText(
    <meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version"/>
    )

    but after start button, the IntentHandler doesn't fired
    why?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice