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

mauron85 / cordova-plugin-background-geolocation Error in Ionic 6 Android #766

Open
ivinantony opened this issue Mar 17, 2022 · 17 comments
Open

Comments

@ivinantony
Copy link

This plugin gives error in ionic 6 android due to android permission

ionic info

Ionic:

Ionic CLI : 6.19.0 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 6.0.12
@angular-devkit/build-angular : 13.2.6
@angular-devkit/schematics : 13.2.6
@angular/cli : 13.2.6
@ionic/angular-toolkit : 6.1.0

Cordova:

Cordova CLI : 11.0.0
Cordova Platforms : android 10.1.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 3 other plugins)

Utility:

cordova-res : 0.15.4
native-run : 1.5.0

System:

ios-deploy : 1.11.4
NodeJS : v16.14.0 (/usr/local/bin/node)
npm : 8.1.0
OS : macOS Monterey
Xcode : Xcode 13.3 Build version 13E113

  • Plugin version: Latest version
  • Platform: Android
  • OS version:
  • Device manufacturer and model:
  • Running in Simulator:
  • Cordova version (cordova -v): 11.0.0
  • Cordova platform version (cordova platform ls):
  • Plugin configuration options:
  • Link to your project:

Context

In Ios its working fine but in android while creating build it shows error of android permission.

Expected Behavior

Its should not have any issue while android build

Actual Behavior

Task :app:mergeDebugResources FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:mergeDebugResources'.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find com.intentfilter:android-permissions:0.1.7.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/intentfilter/android-permissions/0.1.7/android-permissions-0.1.7.pom
- https://repo.maven.apache.org/maven2/com/intentfilter/android-permissions/0.1.7/android-permissions-0.1.7.pom
Required by:
project :app

  • Try:

Possible Fix

   - https://dl.google.com/dl/android/maven2/com/intentfilter/android-permissions/0.1.7/android-permissions-0.1.7.pom
   - https://repo.maven.apache.org/maven2/com/intentfilter/android-permissions/0.1.7/android-permissions-0.1.7.pom
   - no files found here.

Steps to Reproduce

1.create an ionic 6 app
2. installed this plugin
3.create android build
Screenshot 2022-03-16 at 11 14 24 PM

Context

Debug logs

@josuelmm
Copy link

@ivinantony
Copy link
Author

@josuelmm thank you it works but it doesnt give data when app is in background

@ivinantony
Copy link
Author

ivinantony commented Mar 27, 2022

Use this plugin https://github.com/HaylLtd/cordova-background-geolocation-plugin/

@mauron85 @josuelmm i used this plugin but when we allow the permission and after 2,3 second app is crashing in android. do you have any idea? and it doesn't work in background in android after 5 or 6 minutes too

@josuelmm
Copy link

I have this configuration

this.configBackground = {
      stopOnTerminate:false,
      locationProvider:2,
      desiredAccuracy: 0,
      stationaryRadius: 0,
      distanceFilter: 0,
      debug: false,
      interval:3000,
      fastestInterval:2000,
      notificationsEnabled:true,
      startForeground:false,
      notificationTitle:' ',
      notificationText:'Navegación activada',
      notificationIconColor: '#c50707',
      notificationIconLarge:'ic_tracking',
      notificationIconSmall:'ic_tracking',
    };    

Working excelent in background with the application minimized...

@ivinantony
Copy link
Author

@josuelmm thanks. but for me in ios app is getting crashing while allowing the permissio

VIDEO-2022-03-27-19-39-45.mp4

n

@josuelmm
Copy link

josuelmm commented Mar 27, 2022

Request permission of ACTIVITY_RECOGNITION before permission location
Use the plugin https://ionicframework.com/docs/native/android-permissions

@ivinantony
Copy link
Author

thank you so much @josuelmm i will try this.

@josuelmm
Copy link

this.androidPermissions.requestPermission('android.permission.ACTIVITY_RECOGNITION') .then(result => { if (!result.hasPermission){ this.permissionActivity = false; }else{ this.permissionActivity = true; } }) .catch(err=>{ this.permissionActivity = false; });

@ivinantony
Copy link
Author

@josuelmm does it works for you in ios too? for me it works for a 5 minutes in ios and android almost 1 hour. after that this plugin also goes sleep.can i see the way you integrated?

@josuelmm
Copy link

josuelmm commented Mar 28, 2022

You must request permission to run in the background, and notify the client that they must remove the battery saving app.

You do the battery permission with powerOptimization
import { PowerOptimization } from '@awesome-cordova-plugins/power-optimization/ngx';

async requestPermissionLocationForever(){ this.androidPermissions.requestPermission('android.permission.ACCESS_BACKGROUND_LOCATION') .then(result => { if (!result.hasPermission){ this.permissionActivityForever = false; }else{ this.permissionActivityForever = true; } }) .catch(err=>{ this.permissionActivityForever = false; }); }

`async RequestOptimizations(){
this.powerOptimization.RequestOptimizations().then(status =>{
this.IsIgnoringBatteryOptimizations();
this.IsIgnoringDataSaver();
this.HaveProtectedAppsCheck();
})
.catch(error => {
this.permissionBattery = false;
});
}

async IsIgnoringDataSaver(show = false){
this.powerOptimization.IsIgnoringDataSaver().then((status) => {
this.permissionBackground = status;
if (status == false && show == true){
this.powerOptimization.RequestDataSaverMenu().then((result) => {}, (err) => {});
}
}, (err) => {
this.permissionBackground = false;
});
}

async IsIgnoringBatteryOptimizations(show = false){
this.powerOptimization.IsIgnoringBatteryOptimizations().then(status =>{
if (status == false && show == true){
this.showAlertBattery();
}

  if (status == false){
    setTimeout(()=>{
      this.IsIgnoringBatteryOptimizations();
      this.IsIgnoringDataSaver();
      this.HaveProtectedAppsCheck();
    },10000);
  }
  this.permissionBattery = status;
})
.catch(error => {
  this.permissionBattery = false;
});

}

async HaveProtectedAppsCheck(){
this.powerOptimization.HaveProtectedAppsCheck().then((result) => {
this.permissionBatteryProtect = result;
}, (err) => {
this.permissionBatteryProtect = false;
});
}`

@ivinantony
Copy link
Author

@josuelmm thank you so much for your help this all helped me a lot. Thanks for your updates.

@ivinantony
Copy link
Author

@josuelmm is there any directly to the location permission instead of opening the all permissions like in this pic?
image

@ivinantony
Copy link
Author

@josuelmm but that plugin not working in Samsung can you show me an example how you are asking permission and all

@steven-fernandez
Copy link

Use this plugin https://github.com/HaylLtd/cordova-background-geolocation-plugin/

So, is this plugin "@mauron85/cordova-plugin-background-geolocation" to be ignored now and this one to be used instead "https://github.com/HaylLtd/cordova-background-geolocation-plugin/" ? I'm asking because Ionic page points to this plugin.

@josuelmm
Copy link

josuelmm commented Aug 5, 2022

Si correcto @steven-fernandez

@steven-fernandez
Copy link

Si correcto @steven-fernandez

Gracias :)

@seltix5
Copy link

seltix5 commented Dec 10, 2022

Use this plugin https://github.com/HaylLtd/cordova-background-geolocation-plugin/

hi, I try to compile for andorid with that plugin but I get an error too, any tips? I already try to removed/add android platform.

error: cannot access zzbfm
        confidence = activity.getConfidence();
                             ^
  class file for com.google.android.gms.internal.zzbfm not found

image

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

4 participants