Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 90a6537

Browse files
committed
update demo
- activate background monitoring with a button instead of on startup - apply fix suggested in #86
1 parent 433ee57 commit 90a6537

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

demo/app/main-page.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { Accuracy } from "ui/enums";
33
import { EventData } from "data/observable";
44
import { Page } from "ui/page";
55
import { MainViewModel } from "./main-view-model";
6-
const utils = require("utils/utils");
6+
const utils = require("tns-core-modules/utils/utils");
7+
import * as application from "tns-core-modules/application";
78
let locationService = require('./background-service');
89

910
let page: Page;
@@ -14,10 +15,14 @@ declare var com: any;
1415
export function pageLoaded(args: EventData) {
1516
page = <Page>args.object;
1617
page.bindingContext = model;
18+
}
1719

18-
let context = utils.ad.getApplicationContext();
19-
let intent = new android.content.Intent(context, com.nativescript.location.BackgroundService.class);
20-
context.startService(intent);
20+
export function startBackgroundTap() {
21+
if (application.android) {
22+
let context = utils.ad.getApplicationContext();
23+
let intent = new android.content.Intent(context, com.nativescript.location.BackgroundService.class);
24+
context.startService(intent);
25+
}
2126
}
2227

2328
export function enableLocationTap() {

demo/app/main-page.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" class="page">
2-
<GridLayout rows="auto, *, auto">
2+
<GridLayout rows="auto, auto, *, auto">
33
<GridLayout row="0" columns="*, *, *, *" >
44
<Button text="Enable Location" col="0" textWrap="true" tap="enableLocationTap"/>
55
<Button text="Get Current Location" col="1" textWrap="true" tap="buttonGetLocationTap"/>
66
<Button text="Start Monitoring" col="2" textWrap="true" tap="buttonStartTap"/>
77
<Button text="Stop Monitoring" col="3" textWrap="true" tap="buttonStopTap"/>
88
</GridLayout>
9-
<ListView row="1" items="{{ locations }}">
9+
<GridLayout row="1" columns="*" >
10+
<Button text="Start Background thread monitoring" col="0" ios:visibility="collapsed" textWrap="true" tap="startBackgroundTap"/>
11+
</GridLayout>
12+
<ListView row="2" items="{{ locations }}">
1013
<ListView.itemTemplate>
1114
<Label text="{{ $value, latitude + ', ' + longitude + ', ' + altitude }}" />
1215
</ListView.itemTemplate>
1316
</ListView>
14-
<Button text="Clear" row="2" tap="buttonClearTap"/>
17+
<Button text="Clear" row="3" tap="buttonClearTap"/>
1518
</GridLayout>
1619
</Page>

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "3.0.1"
66
},
77
"tns-android": {
8-
"version": "3.2.0"
8+
"version": "3.3.1"
99
}
1010
},
1111
"dependencies": {

src/geolocation.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function _isGooglePlayServicesAvailable(): boolean {
215215

216216
let isLocationServiceEnabled = true;
217217
let googleApiAvailability = com.google.android.gms.common.GoogleApiAvailability.getInstance();
218-
let resultCode = googleApiAvailability.isGooglePlayServicesAvailable(androidAppInstance.foregroundActivity);
218+
let resultCode = googleApiAvailability.isGooglePlayServicesAvailable(androidAppInstance.context);
219219
if (resultCode !== com.google.android.gms.common.ConnectionResult.SUCCESS) {
220220
isLocationServiceEnabled = false;
221221
}

0 commit comments

Comments
 (0)