Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Toybox.Background;
- import Toybox.Graphics;
- import Toybox.Lang;
- import Toybox.System;
- import Toybox.Communications;
- import Toybox.Application;
- import Toybox.WatchUi;
- (:background)
- class BackgroundService extends ServiceDelegate {
- function initialize() {
- ServiceDelegate.initialize();
- }
- function onTemporalEvent() as Void {
- Communications.makeImageRequest(
- "https://services.garmin.com/appsLibraryExternalServices/api/icons/a41f0afd-4802-4406-a8d0-d47336e5d988",
- null,
- {}, method(:onReceiveImage)
- );
- }
- function onReceiveImage(responseCode as Number, data as Null or BitmapReference or BitmapResource) as Void {
- System.println("onReceiveImage: response code = " + responseCode);
- if (responseCode == 200 && data != null) {
- // Storage.setValue(bitmapKey, data); // generates warning/error at typecheck level 2/3
- // a spurious cast is required to make the type checker happy (arguably this type of cast
- // is bad because it should be used sparingly - or not at all, and it gives the dev
- // a false sense of security)
- Storage.setValue(bitmapKey, data as BitmapResource);
- }
- Background.exit(responseCode);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment