0

I'm trying to use background Geolocation service on my Nativescript App. But can't make it work. The main problem is there is no location prop in org.nativescript.demo. -> location < -.BackgroundService26.class

I have tried to use demo app but demo app not working also. I've already tried all the answers from other StackOverflow questions

export function startBackgroundTap() {
    if (application.android) {
        let context = utils.ad.getApplicationContext();
        if (device.sdkVersion >= "26") {
            const jobScheduler = context.getSystemService((<any>android.content.Context).JOB_SCHEDULER_SERVICE);
            const component = new android.content.ComponentName(context, org.nativescript.demo.location.BackgroundService26.class);
            const builder = new (<any>android.app).job.JobInfo.Builder(jobId, component);
            builder.setOverrideDeadline(0);
            return jobScheduler.schedule(builder.build());
        } else {
            let intent = new android.content.Intent(context, org.nativescript.demo.location.BackgroundService.class);
            context.startService(intent);
        }
    }
}

I expected to use geolocation in the background but because of location property not found in org.nativescript.demo I can't use it. org.nativescript.demo is empty object. After this I have tried to update my AndroidManifest.xml file like below

My AndroidManifest.xml file looks like below:

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="__PACKAGE__"
    android:versionCode="1"
    android:versionName="1.0">
    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"/>

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="__APILEVEL__"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:name="com.tns.NativeScriptApplication"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">


        <service android:name="org.nativescript.demo.location.BackgroundService"
            android:exported="false" >
        </service>

        <service android:name="org.nativescript.demo.location.BackgroundService26"
            android:permission="android.permission.BIND_JOB_SERVICE"
            android:enabled="true"
            android:exported="false">
        </service>

        <activity
            android:name="com.tns.NativeScriptActivity"
            android:label="@string/title_activity_kimera"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:theme="@style/LaunchScreenTheme">

            <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.tns.ErrorReportActivity"/>
    </application>
</manifest>

Please help me I need to use it. I tried all the possible actions but nothing works. I thing that something isn't correct in my actions.


Original demo app Nativescript Geolocation


Forked and changed App by me. Geolocation Demo

git clone https://github.com/NativeScript/nativescript-geolocation.git
cd nativescript-geolocation/demo
npm run build.plugin && npm install
tns run android or tns run ios
  • `.class` would be undefined only if when you haven't defined [those classes](https://github.com/NativeScript/nativescript-geolocation/blob/master/demo/app/background-service.ts#L43-L79). Did you try a clean build? – Manoj Jul 08 '19 at 21:42
  • @Manoj Yes of course Deleted Platform folder uninstalled app on the emulator but nothing works. I think that the main problem is AndroidManifest.xml file. ` ` Tried Service name is like -> android:name="org.nativescript.demo.location.BackgroundService26" android:name="com.nativescript.location.BackgroundService26" but none of them works – Heyder Shukurov Jul 08 '19 at 22:11
  • The name should match with the name in your class definition, if it does then it should work. If you still have issues, please share a sample project. – Manoj Jul 08 '19 at 22:26
  • @Manoj Hi. I think I figured out I'm trying to fix my code I'll share my app as soon as I make it work fully – Heyder Shukurov Jul 09 '19 at 07:25
  • @Manoj what's the solution, I'm having the same issue, can't make it work. I try to use the demo with an angular project – Peter Jun 02 '20 at 16:49

0 Answers0