Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App cashes on Android 10 #48

Closed
phiasco12 opened this issue Sep 10, 2021 · 9 comments
Closed

App cashes on Android 10 #48

phiasco12 opened this issue Sep 10, 2021 · 9 comments

Comments

@phiasco12
Copy link

Describe the bug
App Crashes on some devices with Android 10 once the user allows all the permissions.

To Reproduce
Steps to reproduce the behavior:

Simply run this code:

function onDeviceReady() {
  BackgroundGeolocation.configure({
    locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
    desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
    stationaryRadius: 50,
    distanceFilter: 50,
    notificationTitle: 'Background tracking',
    notificationText: 'enabled',
    debug: true,
    interval: 10000,
    fastestInterval: 5000,
    activitiesInterval: 10000,
    url: 'http://192.168.81.15:3000/location',
    httpHeaders: {
      'X-FOO': 'bar'
    },
    // customize post properties
    postTemplate: {
      lat: '@latitude',
      lon: '@longitude',
      foo: 'bar' // you can also add your own properties
    }
  });

  BackgroundGeolocation.on('location', function(location) {


    alert(location);
    // handle your locations here
    // to perform long running operation on iOS
    // you need to create background task
    BackgroundGeolocation.startTask(function(taskKey) {
      // execute long running task
      // eg. ajax post location
      // IMPORTANT: task has to be ended by endTask
      BackgroundGeolocation.endTask(taskKey);
    });
  });

  BackgroundGeolocation.on('stationary', function(stationaryLocation) {
    // handle stationary locations here

    
    alert('st');
  });

  BackgroundGeolocation.on('error', function(error) {
    alert('[ERROR] BackgroundGeolocation error:', error.code, error.message);
  });

  BackgroundGeolocation.on('start', function() {
    alert('[INFO] BackgroundGeolocation service has been started');
  });

  BackgroundGeolocation.on('stop', function() {
    alert('[INFO] BackgroundGeolocation service has been stopped');
  });

  BackgroundGeolocation.on('authorization', function(status) {
    alert('[INFO] BackgroundGeolocation authorization status: ' + status);
    if (status !== BackgroundGeolocation.AUTHORIZED) {
      // we need to set delay or otherwise alert may not be shown
      setTimeout(function() {
        var showSettings = confirm('App requires location tracking permission. Would you like to open app settings?');
        if (showSettings) {
          return BackgroundGeolocation.showAppSettings();
        }
      }, 1000);
    }
  });

  BackgroundGeolocation.on('background', function() {
    alert('[INFO] App is in background');
    // you can also reconfigure service (changes will be applied immediately)
    BackgroundGeolocation.configure({ debug: true });
  });

  BackgroundGeolocation.on('foreground', function() {
    alert('[INFO] App is in foreground');
    BackgroundGeolocation.configure({ debug: false });
  });

  BackgroundGeolocation.on('abort_requested', function() {
    alert('[INFO] Server responded with 285 Updates Not Required');

    // Here we can decide whether we want stop the updates or not.
    // If you've configured the server to return 285, then it means the server does not require further update.
    // So the normal thing to do here would be to `BackgroundGeolocation.stop()`.
    // But you might be counting on it to receive location updates in the UI, so you could just reconfigure and set `url` to null.
  });

  BackgroundGeolocation.on('http_authorization', () => {
    alert('[INFO] App needs to authorize the http requests');
  });

  BackgroundGeolocation.checkStatus(function(status) {
    alert('[INFO] BackgroundGeolocation service is running', status.isRunning);
    alert('[INFO] BackgroundGeolocation services enabled', status.locationServicesEnabled);
    alert('[INFO] BackgroundGeolocation auth status: ' + status.authorization);

    // you don't need to check status before start (this is just the example)
    if (!status.isRunning) {
      BackgroundGeolocation.start(); //triggers start on start event
    }
  });



  // you can also just start without checking for status
  // BackgroundGeolocation.start();

  // Don't forget to remove listeners at some point!
  // BackgroundGeolocation.removeAllListeners();
}

document.addEventListener('deviceready', onDeviceReady, false);

Expected behavior

It should work as its intended to. The above code has been tested on Nexus 5 and Galaxy Tab s7 both Android 11 and it worked fine. but the same code crashes another Nexus 5 Android 10.

Screenshots
N/A

Smartphone (please complete the following information):

  • Device: Nexus 5
  • OS: Android 10
@phiasco12
Copy link
Author

Fixed this issue by requesting android.permission.ACTIVITY_RECOGNITION

@HarelM
Copy link
Collaborator

HarelM commented Sep 10, 2021

I'm using raw provider so it might be the reason I don't see this issue.
Can you send a PR to the documentation in order to clarify this (assuming one only needs to add this to the manifest...)?

@phiasco12
Copy link
Author

I've created a PR.

@HarelM
Copy link
Collaborator

HarelM commented Oct 7, 2021

I don't see one...?

@phiasco12
Copy link
Author

I don't see one...?

somehow my PR ended up here: https://github.com/HarelM/cordova-plugin-background-geolocation/pulls

@erwinyusrizal
Copy link

@phiasco12 I tried your solution above but still the app is crashed

actually it should use android.permission.ACTIVITY_RECOGNITION or it's fine to use this plugin default com.google.android.gms.permission.ACTIVITY_RECOGNITION

@erwinyusrizal
Copy link

hmm... the problem is not coming from this plugin

12-03 12:33:36.901 W/OneSignal(18311): Location permission exists but there was an error initializing: 
12-03 12:33:36.901 W/OneSignal(18311): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/api/Api$zzf;
12-03 12:33:36.901 W/OneSignal(18311): 	at com.google.android.gms.location.LocationServices.<clinit>(Unknown Source:0)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.GMSLocationController.initGoogleLocation(GMSLocationController.java:63)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.GMSLocationController.startGetLocation(GMSLocationController.java:50)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.LocationController.startGetLocation(LocationController.java:310)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.LocationController.getLocation(LocationController.java:271)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignal.startLocationUpdate(OneSignal.java:1004)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignal.startRegistrationOrOnSession(OneSignal.java:979)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignal.doSessionInit(OneSignal.java:968)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignal.init(OneSignal.java:823)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignal.setAppId(OneSignal.java:690)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignal.reassignDelayedInitParams(OneSignal.java:1136)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignal.onRemoteParamSet(OneSignal.java:844)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignal$6.complete(OneSignal.java:1077)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignalRemoteParams.processJson(OneSignalRemoteParams.java:206)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignalRemoteParams.access$100(OneSignalRemoteParams.java:12)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignalRemoteParams$1.onSuccess(OneSignalRemoteParams.java:151)
12-03 12:33:36.901 W/OneSignal(18311): 	at com.onesignal.OneSignalRestClient$5.run(OneSignalRestClient.java:283)
12-03 12:33:36.901 W/OneSignal(18311): 	at java.lang.Thread.run(Thread.java:764)
12-03 12:33:36.901 W/OneSignal(18311): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.api.Api$zzf" on path: DexPathList[[zip file "/data/app/com.itapandgo.app-OXMAkEIMQ8AIAiLVk1OgqQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.itapandgo.app-OXMAkEIMQ8AIAiLVk1OgqQ==/lib/arm64, /system/lib64, /vendor/lib64]]
12-03 12:33:36.901 W/OneSignal(18311): 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
12-03 12:33:36.901 W/OneSignal(18311): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
12-03 12:33:36.901 W/OneSignal(18311): 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

I tried to remove onesignal plugin, and it works fine

@HarelM
Copy link
Collaborator

HarelM commented Dec 3, 2021

Can I close this issue? I don't see issues using android 10 in my app. I might not be using all the possible functionally, but still...

@HarelM
Copy link
Collaborator

HarelM commented Mar 25, 2022

No response, closing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants