Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example doesn't work? #119

Open
wloges opened this issue Nov 20, 2019 · 19 comments
Open

Example doesn't work? #119

wloges opened this issue Nov 20, 2019 · 19 comments

Comments

@wloges
Copy link

wloges commented Nov 20, 2019

I've installed on my Samsung S9 this example
https://github.com/transistorsoft/cordova-background-geolocation-SampleApp/tree/master/examples/cordova-basic
with config shown below. On screen I've got blinking "Stopped". Clicking on "Start" or another buttons change nothing. I would appreciate any suggestions. Maybe another working sample which I can develop for my purposes? Thx in advance.

BGGeo Cordova A sample Apache Cordova application that responds to the deviceready event. Apache Cordova Team
@wloges
Copy link
Author

wloges commented Nov 20, 2019

`

<name>BGGeo Cordova</name>

<description>

    A sample Apache Cordova application that responds to the deviceready event.

</description>

<author email="[email protected]" href="http://cordova.io">
    Apache Cordova Team
</author>
<content src="index.html" />    
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
    <allow-intent href="market:*" />
</platform>
<engine name="android" spec="^6.3.0" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-background-geolocation-lt" spec="https://github.com/transistorsoft/cordova-background-geolocation-lt.git">
    <variable name="LICENSE" value="YOUR_LICENSE_KEY" />
    <variable name="GOOGLE_API_VERSION" value="11.6.0" />
    <variable name="APPCOMPAT_VERSION" value="26.1.0" />
</plugin>
<plugin name="cordova-plugin-device" spec="^1.1.7" />
<plugin name="cordova-plugin-dialogs" spec="^1.3.4" />
`

@christocracy
Copy link
Member

No, that old Cordova example is broken. Make your own hello world.

var BackgroundGeolocation = window.BackgroundGeolocation

See the README

@wloges
Copy link
Author

wloges commented Nov 20, 2019

What about config.xml? This is Ok?

@wloges
Copy link
Author

wloges commented Nov 20, 2019

`

<name>Aplikacja</name>
<description>
    Aplikacja
</description>
<author email="[email protected]">
    Author
</author>
<content src="index.html" />

<preference name="DisallowOverscroll" value="true" />
<preference name="android-minSdkVersion" value="15" />
<preference name="android-targetSdkVersion" value="23" />
<preference name="detect-data-types" value="true" />
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarBackgroundColor" value="#ee6e73" />
<preference name="StatusBarStyle" value="blacktranslucent" />
<platform name="android">
    <allow-intent href="market:*" />
    <icon density="ldpi" src="/res/android/ldpi.png" />
    <icon density="mdpi" src="/res/android/mdpi.png" />
    <icon density="hdpi" src="/res/android/hdpi.png" />
    <icon density="xhdpi" src="/res/android/xhdpi.png" />
</platform>    

<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />

<engine name="android" spec="^6.3.0" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-background-geolocation-lt" spec="https://github.com/transistorsoft/cordova-background-geolocation-lt.git">
    <variable name="GOOGLE_API_VERSION" value="11.6.0" />
    <variable name="APPCOMPAT_VERSION" value="26.1.0" />
</plugin>
<plugin name="cordova-plugin-device" spec="^1.1.7" />
<plugin name="cordova-plugin-dialogs" spec="^1.3.4" />    
`

@christocracy
Copy link
Member

No it's not ok.

<variable name="GOOGLE_API_VERSION" value="11.6.0" />
    <variable name="APPCOMPAT_VERSION" value="26.1.0" />

play-services-location:11.6.0 is over 2 years old. The latest version is 16.0.0.

See https://maven.google.com

@wloges
Copy link
Author

wloges commented Nov 20, 2019

Unfortunately I have still a problem. While testing in browser on desktop I got
'- BackgroundGeolocation is configured and ready to use'. No errors.
On Samsung device last alert is ' - Start ready'. It seems app fails on bgGeo.ready.
I'm really confused. Please tell me what I'm doing wrong?

    var app = {
          initialize: function() {
                document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
           },
    onDeviceReady: function() {
    this.receivedEvent('deviceready');        
   
    var bgGeo = window.BackgroundGeolocation;

    bgGeo.onLocation(function(location) {
        console.log('[event] location: ', location);
    }, function(error) {
        console.warn('[event] location error: ', error);
    });

    bgGeo.onMotionChange(function(location) {
        console.log('[event] motionchange', location);
    });
    
    alert('- Start ready');        
    
    bgGeo.ready({
        desiredAccuracy: bgGeo.DESIRED_ACCURACY_HIGH,     // Highest possible accuracy: GPS + Wifi + Cellular
        distanceFilter: 10,     // Record a location every 10 meters.
        stopOnTerminate: false, // Don't stop tracking when app is terminated.
        url: 'http://www.mysite.com/geoloc.php',
        params: bgGeo.transistorTrackerParams(window.device),
        debug: true,            // Debug sounds & notifications
        autoSync: true,         // Auto sync each recorded location to #url immediately.
        logLevel: bgGeo.LOG_LEVEL_VERBOSE
    }, 
    function(state) {
        bgGeo.start();
        alert('- BackgroundGeolocation is configured and ready to use');
        console.log('- BackgroundGeolocation is configured and ready to use');            
    });        
    
    alert('- End');
  }

@christocracy
Copy link
Member

You can’t use the plugin in the browser.

Test on real device

@wloges
Copy link
Author

wloges commented Nov 20, 2019

On real device application fails on bgGeo.ready.

@christocracy
Copy link
Member

christocracy commented Nov 20, 2019

See wiki Debugging

@wloges
Copy link
Author

wloges commented Nov 20, 2019

More specific please, I'm new in phonegap applications.

@christocracy
Copy link
Member

Click link Wiki followed by Debugging

@wloges
Copy link
Author

wloges commented Nov 21, 2019

Problem solved. Plugin cordova-background-geolocation-lt@~3.3.1 needs cordova ver:^7.0.0.
To achieve it I set <preference name="phonegap-version" value="cli-8.1.1" />
Below is working config.xml for all who want to save many hours for finding right solution :)

           `<?xml version='1.0' encoding='utf-8'?>
           <widget id="com.foo.bar" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>App</name>
<description>
    Application
</description>
<author email="[email protected]">
    Author
</author>
<content src="index.html" />
<preference name="phonegap-version" value="cli-8.1.1" />    
<preference name="DisallowOverscroll" value="true" />
<preference name="android-minSdkVersion" value="19" />
<preference name="android-targetSdkVersion" value="23" />
<preference name="detect-data-types" value="true" />
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarBackgroundColor" value="#ee6e73" />
<preference name="StatusBarStyle" value="blacktranslucent" />
<platform name="android">
    <allow-intent href="market:*" />
    <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
        <application android:usesCleartextTraffic="true" />
    </edit-config>
    <icon density="ldpi" src="www/res/android/ldpi.png" />
    <icon density="mdpi" src="www/res/android/mdpi.png" />
    <icon density="hdpi" src="www/res/android/hdpi.png" />
    <icon density="xhdpi" src="www/res/android/xhdpi.png" />
</platform>
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-plugin-device" spec="^1.1.7" />
<plugin name="cordova-plugin-dialogs" spec="^1.3.4" />
<plugin name="cordova-background-geolocation-lt" spec="~3.3.1">
    <variable name="LICENSE" value="YOUR_LICENSE_KEY" />
    <variable name="GOOGLE_API_VERSION" value="16.0.0" />
    <variable name="APPCOMPAT_VERSION" value="27.1.0" />
</plugin>
 </widget>`

@wloges
Copy link
Author

wloges commented Nov 21, 2019

But the way to full happiness is still long :)
I'v got LICENSE VALIDATION FAILURE although I run the application in debug mode. Chris, what to do to test for free this plugin?

@christocracy
Copy link
Member

Why are you using GOOGLE_API_VERSION 11.6.0?? It's over 2 years old.

I'v got LICENSE VALIDATION FAILURE

It's normal. It's fully functional in DEBUG builds. Ignore everything about "license" until you buy one.

@wloges
Copy link
Author

wloges commented Nov 22, 2019

You are right, it should be
<variable name="GOOGLE_API_VERSION" value="16.0.0" /> <variable name="APPCOMPAT_VERSION" value="27.1.0" />

I didn't mention that my problem was building the application in https://build.phonegap.com :)

@wloges
Copy link
Author

wloges commented Nov 30, 2019

I try to build ios version. After adding to above config a part from https://github.com/transistorsoft/cordova-background-geolocation-lt for ios

    `
    <platform name="ios">
    <config-file parent="NSLocationAlwaysAndWhenInUseUsageDescription" target="*-Info.plist">
        <string>LOCATION_ALWAYS_AND_WHEN_IN_USE_USAGE_DESCRIPTION</string>
    </config-file>
    <config-file parent="NSLocationAlwaysUsageDescription" target="*-Info.plist">
        <string>LOCATION_ALWAYS_USAGE_DESCRIPTION</string>
    </config-file>
    <config-file parent="NSLocationWhenInUseUsageDescription" target="*-Info.plist">
        <string>LOCATION_WHEN_IN_USE_USAGE_DESCRIPTION</string>
    </config-file>
    <config-file parent="NSMotionUsageDescription" target="*-Info.plist">
        <string>MOTION_USAGE_DESCRIPTION</string>
    </config-file>
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
</platform> `

Adobe PhoneGap Build doesn't even start with building ios. Log is empty. Android is Ok.
I would appreciate any ideas.

@christocracy
Copy link
Member

You’re trying to build the SampleApp on PhoneGap?

I don’t use PhoneGap so that’s never been tested by me.

@wloges
Copy link
Author

wloges commented Nov 30, 2019

What way do You recomend to build this app?

@christocracy
Copy link
Member

I use Ionic and Cordova CLI in terminal:

$ ionic cordova build ios

I like to launch iOS directly from XCode; better logging.

For Android

$ ionic cordova run android

PhoneGap is a release build service, not a development build server. I you don't have a Mac, get one. You're a mobile developer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants