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