dpa99c / cordova-diagnostic-plugin Goto Github PK
View Code? Open in Web Editor NEWThis project forked from mablack/cordova-diagnostic-plugin
Cordova/Phonegap plugin to manage device settings
This project forked from mablack/cordova-diagnostic-plugin
Cordova/Phonegap plugin to manage device settings
Is there a reason for only checking GPS when calling isLocationEnabled
on Android?
https://github.com/dpa99c/cordova-diagnostic-plugin/blob/master/src/android/Diagnostic.java#L89
Why not doing something like this?
callbackContext.success((isGpsEnabled() || isNetworkEnabled()) ? 1 : 0);
Just tested it on Android 4.4.4. It worked like a charm.
Because you write something about GPS has to be enabled to get true for isLocationEnabled
in your readme explicitly, i think there must be a reason for this.
Thanks and greetings
wanja
while compiling its showing Uncaught TypeError: Cannot read property 'diagnostic' of undefined
If I may recommend a slight twist to the current NPM package / plugin name cordova.plugins.diagnostic.
How about cordova-plugin-diagnostics?
Most (and the more popular) Cordova and third-party plugin names start with "cordova-plugin-". Seems to be the standard these days.
I am trying to use diagnostic plugin in my ios app built by phonegap Build. It's working fine for android but it's not working in ios.
It is not showing any error in remote debug (console).
I am using following two files to build this app:
index.html and config.xml
(Code is provided: http://stackoverflow.com/questions/35373948/phonegap-diagnostic-plugin-is-not-working-in-iphone)
I am not getting any error. I reasearched alot about this issue but no vain. I'll really appreciate any response.
I want to know, Can we open Location setting in iPad4 wifi? I think there have code for GPS location enable or not. What we do for open the Location Setting?
On Android, if you install the app for the first time, the first call to requestLocationAuthorization always returns GRANTED without waiting for the user choice.
I debugged this further, and turns out the 'GRANTED' is returned by mistake by combineLocationStatuses(). If I use requestRuntimePermission directly in my program, then the first call always returns 'undefined' (it correctly shows the choice dialog, but returns before the user chooses an option). All subsequent call to requestRuntimePermissions() work properly as documented.
platforms/android/src/cordova/plugins/Diagnostic.java:411: cannot find symbol
symbol : method shouldShowRequestPermissionRationale(android.app.Activity,java.lang.String)
location: class android.support.v4.app.ActivityCompat
boolean showRationale = ActivityCompat.shouldShowRequestPermissionRationale(this.cordova.getActivity(), androidPermission);
^
platforms/android/src/cordova/plugins/Diagnostic.java:565: cannot find symbol
symbol : method shouldShowRequestPermissionRationale(android.app.Activity,java.lang.String)
location: class android.support.v4.app.ActivityCompat
boolean showRationale = ActivityCompat.shouldShowRequestPermissionRationale(this.cordova.getActivity(), androidPermission);
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /platforms/android/src/cordova/plugins/Diagnostic.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
100 warnings
:compileDebugJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileDebugJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED```
Hi there, I have a question
I am recording audio on Android, and I noticed the requestMicrophoneAuthorization()
is iOS only
What happens if I need this permission on Android Marshmallow?
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Your plugin does not provide any method to check if that permission is granted on Android or am I missing something?
It seems checkForInvalidPermissions is getting called and "result" is undefined:
var valid = true, invalidPermissions = [];
...
if(invalidPermissions.length > 0) {
errorCallback("Invalid permissions specified: "+result.invalidPermissions.join(", "));
}
Does the variable "result" need to be there?
Hi everyone,
Just a quick question did any body of you encountered a build error after installing crosswalk + cordova diagnostic.
Or do you know any other plugin that I can use to enable gps/location.
Happy Coding <3 :D
I upgraded to cordova-ios 4.0.1 post which my ionic app is failing to build
There are many plugins which are failing out of which diagnostic is also the one.
i had posted the issue on cordova-ios issue tracker and @shazron have reverted with suggestions to fix the plugin as many deprecated methods have been removed in cordova-ios 4.0.1.
https://issues.apache.org/jira/browse/CB-10310
Info on the code breaks and fixing them
http://cordova.apache.org/announcements/2015/12/08/cordova-ios-4.0.0.html
http://cordova.apache.org/news/2015/11/24/plugins-release.html
Also attaching the exact error for the plugin with [email protected]
hi @dpa99c
I am using PGB 5.2.0 with your plugin with version 2.1.0 + iOS 9.0.2 (13A452)
all function perfect work in addition to "registerLocationAuthorizationStatusChangeHandler"
cordova.plugins.diagnostic.registerLocationAuthorizationStatusChangeHandler(function(status){
alert("Location authorization status changed to: "+status);
});
no any alert appear after I change the location service on to off or off to on
hi @dpa99c
I am using PGB cli-5.2.0 with your latest plugin 2.2.3 from npm + Android 4.4.2
https://www.npmjs.com/package/cordova.plugins.diagnostic
when I am using "setWifiState" and "setBluetoothState"
it all trigger the error callback
and output these message
Value null at 0 of type org.json.JSONObject$1 cannot be converted to boolean
could I ask what the words true meaning?
If I access the plugin through cordova.plugins.diagnostic I get an error because is undefined.
I solved it accessing the plugin like this -> window.Diagnostic (with a capital D)
I don't know what is the state of android 6, but I know they'll use the "same" permissions system than iOS.
Will this library support them ?
I have Apache Cordova project in VS 2013.5, I am trying to this plugin from config .xml and it gives build time error that 'Uh - oh' in MDAVSCLI .Any solution for this ?
Hi,
I am using the cordova plugin in my MobileFirst Platform foundation 7.1
(eclipse plugin). I have installed the cordova-diagnostic-plugin malually.
When I try to run the project I face following error
Uncaught ReferenceError: module is not defined diagnostic.js 669
So can you help me to understand why this issue is been occured?
I have done following workaround to resolve the issue.
window.Diagnostic = new Diagnostic();
Is it possible to cherry-pick the different "uses-permissions" for Android? Would like to keep them to a minimum as I'm only using one. Looking through the source and I'm wondering whether this will break the plugin.
Is there a way to send the user directly to Settings->Privacy->Location Services on iOS? Just like switchToLocationSettings works for Android.
cordova.plugins.diagnostic.switchToSettings has a different purpose for iOS.
I am wondering if this can be a doable and possible enhancement for this plugin or if there is any other alternative.
Background: https://forum.ionicframework.com/t/ios-plugin-for-sending-user-to-settings-privacy-location-services/42273
In google maps, when you have the app open and GPS disabled, it asks you if you would like to enable it and does so within the application without having to go to settings.
Would this be possible to implement by any chance?
Returns 0
or 1
and not false
or true
as labeled in the documentation
Removal of Camera permission line prevents apps from requesting access for Camera support.
It only requests Storage. All of the status checks for Camera then return GRANTED but checking the App settings, Camera is not, only Storage.
Specifying 2.3.10 in phonegap fixes issue.
I’m not sure if it’s only my phone, tested on Android 6.0, HTC One M8.
Hi,
I´m developing an app using ionic, and I have used this plugin to detect if the user has the location enabled or not.
I was having an exception problem if the android version was earlier than kitkat (19). So I have modified the plugin code to get it works, but I don´t know if my changes are correct.
In the function getLocationMode() I have change the code with this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
return Settings.Secure.getInt(this.cordova.getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE);
}else{
LocationManager locationMgr = (LocationManager) this.cordova.getActivity().getSystemService(Context.LOCATION_SERVICE);
if(!locationMgr.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && !locationMgr.isProviderEnabled(LocationManager.GPS_PROVIDER)){
return 0;
}else{
if(locationMgr.isProviderEnabled(LocationManager.GPS_PROVIDER)){
return 3;
}else{
if(locationMgr.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
return 2;
}else{
return 0; //no provider detected
}
}
}
}
I have change the functions isgpslocationenabled and isnetworklocationenabled too, because there was a problem with Settings.Secure. I don´t lnow if is there another way to solve my problem.
Thanks and greetings
Hello !
First of all, thank you (again) for that good job !
It works like a charm and it works around all the plugins not up to date with android 6 permissions system !
Still it could be an even more "ultimate" plugin if other permissions types were also implemented.
For example :
This is of course just a suggestion, it's already pretty cool to have what you already did :)
I just wish i had more native coding knowledge to help you insteady of just suggesting/requesting things..
Anyways,
Thank you again for sharing your work !
Have a good day !
in your example the diagnostic.js
Diagnostic.requestCameraAuthorization = function(successCallback, errorCallback){
Diagnostic.requestRuntimePermission(successCallback, errorCallback, Diagnostic.runtimePermission.CAMERA);
};
is right,but when we use cordova insall the plugin the method is
Diagnostic.requestCameraAuthorization = function(successCallback, errorCallback){
function onSuccess(statuses){
successCallback(combineCameraStatuses(statuses));
}
Diagnostic.requestRuntimePermissions(onSuccess, errorCallback, [
Diagnostic.runtimePermission.READ_EXTERNAL_STORAGE
]);
};
is that paste wrong ???
Hi,
I have used plugin in worklight 7.1 hybrid project, when I run the project following error has occured
On browser- Uncaught ReferenceError: module is not defined
on android device - undefined is not a function
When I made following changes in diagnostic.js it worked fine
window.Diagnostic = window.Diagnostic || {};
window.Diagnostic = new Diagnostic();
Hi,
I'm not entirely sure that the runtime permissions on Android 6.0 work. I added everything as told, received granted everytime i requested the permissions ( build was set on Android sdk 23 and it was the only version).
Then i request my current position, i always receive:
message: application does not have sufficient geolocation permissions.
But i requested the runtime permissions earlier on, and the return was:
Successfully requested location authorization
My Androidmanifest was the same as the one when i had sdk 22 as target, so i didn't remove anything there. The issue seemed the runtime permissions.
Could you add a button on your example app which requests your current location? Because i think it doesn't receive the right permissions somehow.
- Add the geolocation plugin
var posOptions = { timeout: 35000, enableHighAccuracy: true, maximumAge: 5000 };
navigator.geolocation
.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
}, function (err) {
console.log(err.code + " " + err.message);
});
I'm requesting a permission, and a couple of other things (isCameraAuthorized etc.) all at the same time, and sometimes I don't get a callback (not even a failure) - almost always on my requestRuntimePermission.
Is this an issue, or is it considered best practice to chain these requests rather than async?
I am using Cordova 5.1.1 against Android Marshmallow. Once Cordova has initialized I am checking for Camera access like so:
cordova.plugins.diagnostic.getCameraAuthorizationStatus(
function (access) {
$constants.HasCameraAccess = access;
},
function (error) {
alert("Camera Authorization Error: " + error);
}
);
Then when the user attempts to scan a barcode with the application I am checking my HasCameraAccess variable and if it is set to "NOT_REQUESTED" then I am attempting to prompt for access like so:
cordova.plugins.diagnostic.requestCameraAuthorization(
function (access) {
$constants.HasCameraAccess = access;
},
function (error) {
alert("Camera Authorization Error: " + error);
}
);
The issue that I am having is that the pop up to ask the user for permission is never showing, and a second attempt at requestCameraAuthorization is always returning "DENIED_ALWAYS".
Any ideas as to what I'm doing wrong?
Thanks,
Eric
When using requestLocationAuthorization in iOS with and without passing in "when_in_use"
cordova.plugins.diagnostic.requestLocationAuthorization(function(){
console.log("Successfully requested location authorization always");
}, function(error){
console.error(error);
}, "when_in_use");
Error in Error callbackId: Diagnostic786250294 : ReferenceError: Can't find variable: error
Hello. I have cordova/ionic app. If after installing the app, I go to it's settings and disable location services, I always get successCallback: '1' when doing cordova.plugins.diagnostic.isLocationEnabled. Is it expected? Can I somehow check if location services permission is turned off for current app?
I need help with a compile error on Phonegap Build caused by this plugin.
My error is the same described here: http://community.phonegap.com/nitobi/topics/error-on-cli-5-2-0-gradle-android-build-in-values-v23-values-xml
"That plugin requires Android SDK-23. I am not sure whether or not PGB already uses this SDK version."
"we are not on Android SDK-23 - yet!"
How can I bypass this?
Thanks!
Gettiing the following error after calling 'requestLocationAuthorization' method on iOS 7 device:
[CLLocationManager requestWinInUseAuthorization]:
unrecognized selector sent to instance 0x194812c0
Hi,
Since the version 2.1.0 of this plugin and IOS improvements, I can't use IsLocationEnabled on my Iphone 4s (IOS v9.0.2).
If I use version 2.0.1, all is working fine
Hello,
I have a crach in iPhone4 and iPhone4s iOS 7.1.2. I can reproduce 100% on call cordova.plugins.diagnostic.switchToSettings. In other devices is working perfect. I'm using Phonegap Build.
Thanks !
using cordova.plugins.diagnostic.requestLocationAuthorization() on iOS, cordova 6.1.1 -- the success callback fires when the function is called, not when the user picks a choice, meaning I still must use the event listener to actually get user choice.
Do you think it would make sense to detect notifications permissions in this plugin ?
On Android Marshmallow, The plugin is returning "Granted" even when I go to settings and disable that specific permission. In my case, I got a "Granted" on camera runtime permission check even when I had disabled it through settings. Android is unable to open camera post that though since the permission is in reality disabled.
The plugin is failing with an invalid sendPluginResult on iOS and breaks the build.
User if this is a bug or a problem with the wording in the documentation.
The success callback function of requestLocationAuthorization is being called immediately / as soon as the dialog is shown on iOS. My expectation is that it must be called once the user allows usage of device location, as it already does so on Android.
Experienced on a iOS 9.3 iPhone 6.
- (void) isLocationEnabled: (CDVInvokedUrlCommand*)command
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSLog(@"Loading Location status...");
CDVPluginResult* pluginResult;
if([self isLocationEnabled] && [self isLocationAuthorized]) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:1];
}
else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:0];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
dispatch_async(dispatch_get_main_queue(), ^{
});
});
}
- (BOOL) isLocationEnabled
{
if([CLLocationManager locationServicesEnabled]) {
NSLog(@"Location is enabled.");
return true;
} else {
NSLog(@"Location is disabled.");
return false;
}
}
- (BOOL) isLocationAuthorized
{
if([CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied) {
NSLog(@"This app is authorized to use location.");
return true;
} else {
NSLog(@"This app is not authorized to use location.");
return false;
}
}
Checked timestamps entries with NSLog for 'isLocationEnabled' and 'isLocationAuthorized', it takes more than 10 seconds to execute isLocationEnabled and 1 second to execute isLocationAuthorized.And also giving warning '['Diagnostic'] took '52807.718994' ms. Plugin should use a background thread'. Mostly happened when we resume the app from background. Could anyone please answer why it is taking more time to execute isLocationEnabled?
Xcode Log:
2015-11-17 19:35:58.026 AppName Loading Location status...
2015-11-17 19:36:50.481 AppName Location is enabled.
2015-11-17 19:36:50.816 AppName This app is authorized to use location.
2015-11-17 19:36:50.833 AppName THREAD WARNING: ['Diagnostic'] took '52807.718994' ms. Plugin should use a background thread.
Hi,
How do you guys do to check if location was enabled after switch to location settings screen?
Because the user could just get back to the app without enable the GPS right? We have to check again and again until have sure that is enable.
Maybe if switchToLocationSettings returns a promise... I don't know
How did you solve that?
Thank you!
I am using the following code to check for permissions on Marshmallow before taking a picture:
//check permission
window.cordova.plugins.diagnostic.isCameraAuthorized(function(response) {
if (response) {
$rootScope.permissions.camera = true;
_openCamera();
} else {
// request permission
cordova.plugins.diagnostic.requestCameraAuthorization(function(permission) {
if (permission === 'GRANTED') {
$rootScope.permissions.camera = true;
_openCamera();
}
}, function(error) {
console.error(error);
});
}
}, function(error) {
console.log(error);
});
_openCamera();
will run the code to open the camera, but the app crashes with:
Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.camera2/com.android.camera.CaptureActivity clip={text/uri-list U:file:///storage/emulated/0/Android/data/uk.ac.imperial.epicollect5.ionic/cache/.Pic.jpg} (has extras) } from ProcessRecord{99d2ee 7527:uk.ac.imperial.epicollect5.ionic/u0a79} (pid=7527, uid=10079) with revoked permission android.permission.CAMERA
I get the popup, I tap allow, the permission is GRANTED but still the camera crashes. If I look at the app permission settings, camera is still off after granting permission.
Any suggestions?
adding <gap:plugin name="cordova.plugins.diagnostic.api-22" source="npm" /> in config.xml is giving build error.
Device Model: SproutChannelCubby
Android version: 4.4.2
Processor: QuadCore-A31
Phonegap Build verison: cli-5.2.0
ERROR Exception occured: WifiService: Neither user 10137 nor current process has android.permission.ACCESS
To be clear, the device only has wifi and the wifi is on.
I made this call:
cordova.plugins.diagnostic.isWifiEnabled()
Source code
Downloadable Build
Did a cordova plugin add cordova.plugins.diagnostic
and the resultant www/android/diagnostic.js doesn't have that method even though it's in the README.md. Guess npm hasn't been updated?
I'll do add this github repo in the plugin path and it should work.
hi @dpa99c
I use PGB cli-5.2.0 with your latest plugin 2.3.2
but it will cause Android build fail
2.3.0 is build fine
here is my log
http://pastebin.com/embed_iframe.php?i=AnBHDiGa
Hi, I'm not clear from reading the documentation about using the latest version to call isLocationEnabled()
. If I use the latest version and build using SDK version 23, will the function return the correct value when called from both Marshmallow (API 23) and a KitKat (API 19) devices?
First, thanks for your work. I was looking for this plugin.Unfortunately, I ran into two problems.
I install the plugin follow the instruction in my local:
$ cordova plugin add cordova.plugins.diagnostic
Fetching plugin "cordova.plugins.diagnostic" via cordova plugins registry
npm http GET http://registry.cordova.io/cordova.plugins.diagnostic
npm http 200 http://registry.cordova.io/cordova.plugins.diagnostic
npm http GET http://cordova.iriscouch.com/registry/_design/app/_rewrite/cordova.plugins.diagnostic/-/cordova.plugins.diagnostic-1.1.0.tgz
npm http 200 http://cordova.iriscouch.com/registry/_design/app/_rewrite/cordova.plugins.diagnostic/-/cordova.plugins.diagnostic-1.1.0.tgz
Installing "cordova.plugins.diagnostic" for android
Installing "cordova.plugins.diagnostic" for ios
The version is 1.1.0, but not 2.1.0 listed in npm?! Some how the cordova use the version in Cordova Registry. Any idea? BTW, I also used phonegap build too(<gap:plugin name="cordova.plugins.diagnostic" source="npm" />), but I cannot validate the version thru their UI.
2 problem:
When my gps settings is totally off(GPS+wifi), the following code will still return me success, having an alert claiming the device is gps ready:
function checkLocationState(){
cordova.plugins.diagnostic.isLocationEnabled(
function(){alert("ready?");},
function(err){
var settingFxn;
if($rootScope.UTIL.osType = "android")
settingFxn = cordova.plugins.diagnostic.switchToLocationSettings;
else
settingFxn = cordova.plugins.diagnostic.switchToSettings;
settingFxn(
function(){
alert("Successfully switched to Settings app");
},
function(error){
alert("The following error occurred: "+error);
});
});
}
document.addEventListener('resume', checkLocationState, false);
document.addEventListener('deviceready', checkLocationState, false);
The problem is in iOS and Android.
Just FYI, we use local build to test Android and phonegap build to test iOS.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.