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

How Can I Know If GPS is Enabled and If not How Can I open settings from APP #350

Closed
vedantterkar opened this issue May 23, 2017 · 23 comments

Comments

@vedantterkar
Copy link

vedantterkar commented May 23, 2017

I want to know if GPS is enabled and app is able to access the GPS, If any of this is not true, Then I'll like to open settings. Is this possible?

Environment

  • Plugin version: 2.7.0

  • Platform: Android

  • OS version: 6

  • Cordova version (cordova -v): 6.5.0

  • Plugin config

backgroundGeolocation :any;
intervalInMilliseconds = 60 * 1000; //1 min
 this.config = {
      desiredAccuracy: 10,
      stationaryRadius: 5,
      distanceFilter: 0,
      debug: false,
      stopOnTerminate: false,
      startForeground: true,
      locationProvider: 1,
      interval: intervalInMilliseconds,
      locationUpdateInterval: intervalInMilliseconds,
      fastestInterval: intervalInMilliseconds / 2,
      activitiesInterval: intervalInMilliseconds / 2,
      stopOnStillActivity: false,
      pauseLocationUpdates: false,
      activityType: 'AutomotiveNavigation',
      notificationText: this.notificationText,
      notificationTitle: this.notificationTitle
    };


        platform.ready().then(() => {
          alert("Bingo!");
          backgroundGeolocation = (<any>window).BackgroundGeolocation;
           backgroundGeolocation.on("location", this.setLocation, this.handleError );  
           backgroundGeolocation.configure(this.config, this.setLocation, this.handleError);
        });
setLocation(location: any) {
backgroundGeolocation.start(); // I want to check GPS settings before calling start
console,log("location Triggered!");
   backgroundGeolocation.finish();
    
  }
handleError(error:any)
{
console.error(error);
}

Expected Behavior

I want to check GPS/location settings before start (if location is not enabled, We can show some alert or open settings)

Actual Behavior

It just asks that APP requires Permission to access Location.

Context

I want to check GPS/location settings before start (if location is not enabled, I want to open settings) Is it possible?

@christocracy
Copy link
Member

Listen to providerchange event.

@vedantterkar
Copy link
Author

@christocracy ,
Is there any way to open location settings page?

Any API equivalent to: BackgroundGeolocation.showLocationSettings();?

@christocracy
Copy link
Member

No, but I believe there are 3rd-party plugins that can do this.

@vedantterkar
Copy link
Author

vedantterkar commented May 23, 2017

providerChange event listener is not working in my case..

I've written it like:

backgroundGeolocation.on("location", this.setLocation.bind(this), this.handleError.bind(this) );  
           /**RESPONSE FROM christocracy TO DETECT GPS CHANGES */
           backgroundGeolocation.on('providerchange', function(provider) {
             debugger
              console.log('- Provider Change: ', provider);
              console.log('  enabled: ', provider.enabled);
              console.log('  gps: ', provider.gps);
              console.log('  network: ', provider.network);
              console.log('  status: ', provider.status);
            if(provider.status != 3) 
            {
              alert("LOcation settings changed");
            }
          }); 
backgroundGeolocation.configure(this.config, this.setLocation.bind(this), this.handleError.bind(this) );  

Still when I turn off GPS or If I turn it on again.. Nothing is getting printed in logs and no Alert is coming.

Also There is one more issue, .configure() method always calls failureCallbackFn insted of calling SuucessCallbackFn

Can you please help in this?

@christocracy
Copy link
Member

You're not attempting to boot this in the browser, are you?

@christocracy
Copy link
Member

What is the error returned from failureCallbackFn?

@christocracy
Copy link
Member

#configure failing is the issue. If #configure fails, nothing will work.

@vedantterkar
Copy link
Author

vedantterkar commented May 23, 2017 via email

@christocracy
Copy link
Member

Show me your $ cordova plugins

@vedantterkar
Copy link
Author

vedantterkar commented May 23, 2017 via email

@christocracy
Copy link
Member

Show me your $ cordova plugins and I'll tell you exactly what's going on.

@vedantterkar
Copy link
Author

vedantterkar commented May 24, 2017

@christocracy,
Here is output of cordova plugins command:

$cordova plugins
cordova-background-geolocation-lt 2.7.1 "BackgroundGeolocation"
cordova-custom-config 3.1.2 "cordova-custom-config"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-background-fetch 4.0.2 "CDVBackgroundFetch"
cordova-plugin-camera 2.2.0 "Camera"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-console 1.0.6 "Console"
cordova-plugin-device 1.1.5 "Device"
cordova-plugin-dialogs 1.3.3 "Notification"
cordova-plugin-mauron85-background-geolocation 2.2.5 "CDVBackgroundGeolocation"
cordova-plugin-network-information 1.3.1 "Network Information"
cordova-plugin-splashscreen 4.0.2 "Splashscreen"
cordova-plugin-sqlite-2 1.0.4 "SQLitePlugin"
cordova-plugin-statusbar 2.2.2 "StatusBar"
cordova-plugin-whitelist 1.3.2 "Whitelist"
cordova.plugins.diagnostic 3.3.3 "Diagnostic"
ionic-plugin-deeplinks 1.0.14 "Ionic Deeplink Plugin"
ionic-plugin-keyboard 2.2.1 "Keyboard"

@vedantterkar
Copy link
Author

vedantterkar commented May 24, 2017

@christocracy
Also Is there any way to get location after every "n" minutes on IOS?
I know there is locationUpdateInterval But I think it is Android specific. Any Idea for IOS?

@christocracy
Copy link
Member

christocracy commented May 24, 2017

You problem is this:

cordova-plugin-mauron85-background-geolocation 2.2.5 "CDVBackgroundGeolocation"

You need to remove that. You can't use both Mauron85's old fork in addition to this plugin.

This plugin has a different API and config params. You need to start from scratch implementing my plugin. Your Javascript code for Mauron85's version is incompatible with mine.

@christocracy
Copy link
Member

Also Is there any way to get location after every "n" minutes on IOS?
I know there is locationUpdateInterval But I think it is Android specific. Any Idea for IOS?

My plugin includes my iOS background-fetch plugin as a dependency:

cordova-plugin-background-fetch 4.0.2 "CDVBackgroundFetch"

This plugin will fire its fetch event typically every 15min, even while the device is stationary.

@vedantterkar
Copy link
Author

vedantterkar commented May 24, 2017

Can I make it customizable, Say If I want location after every 2 mins (ios)? Can I do it?

Thanks for your help :).

@christocracy
Copy link
Member

iOS background-fetch API's minimum interval is 15 min.

@vedantterkar
Copy link
Author

Hi, I uninstalled another plugin and tested this one.
It works fine.

Now Just one question; Every time I call configure it asks the user for location sharing permission; though my app has been given location sharing permission as "Always"?

I don't want to show location sharing permission dialog box if permission is already given.

Any idea How can we do it?

Really Appreciate your help.

@christocracy
Copy link
Member

The plugin does not ask for location permission if already granted.

@christocracy
Copy link
Member

The question for you is: "why is the location permission being revoked causing the plugin to have to re-ask for permission?"

@vedantterkar
Copy link
Author

vedantterkar commented May 25, 2017

@christocracy ,

I was uninstalling and re-installing app for testing purpose and thats why it was asking for location permissions again and again.

Now That issue is resolved.

As I mentioned earlier

@christocracy
Also Is there any way to get location after every "n" minutes on IOS?
I know there is locationUpdateInterval But I think it is Android specific. Any Idea for IOS?

As Location update interval is 15mins on IOS; I tried to use .on("heartbeat")API with heartbeatInterval: 60 (60 secs).

It works fine in both IOS and Android in foreground and background mode; But There is one issue which I noticed recently; After some time Let us say 10mins; instead of firing heartbeat event after specified interval (60sec) It was firing it after much larger time of 5minutes.

Is it because of my config settings?

 this.config = {
      desiredAccuracy: 10,
      stationaryRadius: 0,
      distanceFilter: 0,
      debug: true,
      stopOnTerminate: false,
      startForeground: true,
      locationProvider: 1,
      locationUpdateInterval: 60 * 1000
      fastestInterval: (60 * 1000) / 2,
      activitiesInterval: (60 * 1000) / 2,
      stopOnStillActivity: false,
      pauseLocationUpdates: false,
      activityType: 'AutomotiveNavigation',
      notificationText: this.notificationText,
      notificationTitle: this.notificationTitle,
      useSignificantChangesOnly: false,
      locationAuthorizationRequest: 'Always',
      activityRecognitionInterval: 100,
      heartbeatInterval: 60,
      preventSuspend: true,
      trackingMode: 'location'
     
    };

Or is it something else? Thanks in advance.

and as mentioned in documentation;
.on("location") will be fired as soon as new location is detected, That means on IOS it'll be fired too right? or will it be fired after 15mins only even if .on('location') is changed?

And what is the minimum distance needs to be travelled to trigger .on('location')

@christocracy
Copy link
Member

You are getting way off topic from the original subject "How Can I Know If GPS is Enabled and If not How Can I open settings from APP".

This issue is closed. I will talk no further on this thread.

@vedantterkar
Copy link
Author

vedantterkar commented May 25, 2017

@christocracy,
Thanks.
I'll create new thread for this.

@christocracy

Created a new Thread: #354

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

No branches or pull requests

2 participants