Guest User

makeimagerequest

a guest
Dec 21st, 2024
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import Toybox.Background;
  2. import Toybox.Graphics;
  3. import Toybox.Lang;
  4. import Toybox.System;
  5. import Toybox.Communications;
  6. import Toybox.Application;
  7. import Toybox.WatchUi;
  8.  
  9. (:background)
  10. class BackgroundService extends ServiceDelegate {
  11. function initialize() {
  12. ServiceDelegate.initialize();
  13. }
  14.  
  15. function onTemporalEvent() as Void {
  16. Communications.makeImageRequest(
  17. "https://services.garmin.com/appsLibraryExternalServices/api/icons/a41f0afd-4802-4406-a8d0-d47336e5d988",
  18. null,
  19. {}, method(:onReceiveImage)
  20. );
  21. }
  22. function onReceiveImage(responseCode as Number, data as Null or BitmapReference or BitmapResource) as Void {
  23. System.println("onReceiveImage: response code = " + responseCode);
  24. if (responseCode == 200 && data != null) {
  25. // Storage.setValue(bitmapKey, data); // generates warning/error at typecheck level 2/3
  26.  
  27. // a spurious cast is required to make the type checker happy (arguably this type of cast
  28. // is bad because it should be used sparingly - or not at all, and it gives the dev
  29. // a false sense of security)
  30. Storage.setValue(bitmapKey, data as BitmapResource);
  31. }
  32. Background.exit(responseCode);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment