Ionic Diagnostic Plugin always returns “DENIE_ALWAYS” on android - android

I'm using Ionic 4 and all my IOS diagnostic permissions are working..
But on android if I request access to anything (lets say CAMERA for example). It returns a DENIE_ALWAYS response. If I go into the settings>app settings> permissions It is saying that the app doesn't need any permissions. I've verified the permissions exist in the androidManifest.xml. But I am unable to ever prompt to user for permissions.
Any help on this would be appreciated.
Example code
this.diagnostic.getCameraAuthorizationStatus()
.then( async (status) => {
debugger;
if (status === this.diagnostic.permissionStatus.GRANTED
|| status === this.diagnostic.permissionStatus.GRANTED_WHEN_IN_USE) {
this.appSettings.camera.enabled = true;
this.updateAppSettings();
} else if (status === this.diagnostic.permissionStatus.NOT_REQUESTED) {
this.diagnostic.requestCameraAuthorization()
.then((res) => {
// HERE IS ALWAYS DENIE_ALWAYS WITHOUT EVER PROMPTING USER
debugger;
if (res === this.diagnostic.permissionStatus.GRANTED
|| res === this.diagnostic.permissionStatus.GRANTED_WHEN_IN_USE) {
this.appSettings.camera.enabled = true;
this.updateAppSettings();
} else {
this.appSettings.camera.enabled = false;
this.updateAppSettings();
}
});

I finally found the answer after hours of searching..
Under the platforms>android>AndroidManifest.xml you need to make sure this includes all your permissions
<uses-permission android:name="android.permission.CAMERA" />
But for some reason this AndroidManifest wasn't the same that was being used under
platforms > android> app> src > main> AndroidManifest.xml
And a build wasn't updating that file either. So I copied the correct AndroidManifest.xml to that path and it started working.
This was way harder than it should have been.. I don't know why adding and removing the platform or rebuilding wouldn't updating that manifest..

Related

react-native-beacons-manager Not showing any beacons on Android

Using https://github.com/MacKentoch/react-native-beacons-manager
Works lovely on iOS, however, on Android, after I begin ranging beacons, the beacon array shows up with nothing in it (there are 6 beacons next to me and they all show up on iOS).
Here's what I'm doing:
componentDidMount() {
// Start detecting all iBeacons in the nearby
Beacons.detectIBeacons();
Beacons.startRangingBeaconsInRegion('Estimotes', 'B9407F30-F5F8-466E-AFF9-25556B57FE6D').then((data)=>{
console.log(data);
}).catch((reason) => {
console.log(reason);
});
// Print a log of the detected iBeacons (1 per second)
DeviceEventEmitter.addListener('beaconsDidRange', (data) => {
console.log(data);
});
}
In my console, I get this:
{beacons: Array(0), uuid: "b9407f30-f5f8-466e-aff9-25556b57fe6d", identifier: "Estimotes"}
I left the UUID of the Estimotes as default so this should work. Using a Samsung Galaxy S8+ for testing. Am I doing anything wrong coding wise here? Are there additional permissions on Android that I am missing? Bluetooth and Location services are on.
Alright, I figured it out. Newer versions of android require additional permissions. In your Manifest, throw this guy in there:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
.... if you're using react-native-kontaktio (which is better than react-native-beacons-manager imo) you'll also need to throw this in your Manifest in the <application> section:
<service android:name="com.kontakt.sdk.android.ble.service.ProximityService"/>
Then in your app.js you'll need to request the permission like () make sure you
import PermissionsAndroid
from 'react-native'
:
componentDidMount() {
try {
const granted = PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
'title': 'Location Permission',
'message': 'Activeev needs to access your location.'
}
)
console.log('here', granted);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("Location Permitted")
} else {
console.log("Location permission denied")
}
} catch (err) {
console.warn(err)
}
}
Working like a charm now. Hope this helps someone else.

Appcelerator SDK 5.4 Android Calendar permission on Android 6

I've read a really lot of posts yet, but the problem still occurs...
My app needs calendar permission, and this wil work fine till Android 5.
In my trap.xml in the permissions ar set as followed:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/>
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
</manifest>
</android>
When I try to set the permission like I found on Jira:
function calenderTask() {
if (Ti.Calendar.hasCalendarPermissions()) {
showCalendars(Ti.Calendar.selectableCalendars);
} else {
Ti.Calendar.requestCalendarPermissions(function(e) {
if (e.success) {
showCalendars(Ti.Calendar.selectableCalendars);
} else {
Ti.API.error(e.error);
alert('Access to calendar is not allowed');
}
});
}
}
function showCalendars(calendars) {
for (var i = 0; i < calendars.length; i++) {
Ti.API.info("Calender: "+calendars[i].name);
}
}
calenderTask();
only after a fresh install on the device (Samgung S7, Android 6) there is some action when I place an alert in the code.
The next run it looks like the code is ignored.
And... most important of all, there is no permissions set.
When I manually set the permission in the settings of my device, the app works fine.
Please is there somebody with a solution for me?
I'm also trying to find a better way of checking Calendar permissions on Android 6.
Meanwhile, I'm using this code to send the user right to the app settings on a dialog:
var dialog = Ti.UI.createAlertDialog();
dialog.message = 'Please check your calendar permissions';
dialog.cancel = 1;
dialog.buttonNames = ['Settings', 'Cancel'];
dialog.addEventListener('click', function(e){
var intentData = {action: "android.settings.APPLICATION_DETAILS_SETTINGS", data: "package:" + Ti.App.getId()};
var flags = [ Ti.Android.FLAG_ACTIVITY_NEW_TASK, Ti.Android.FLAG_ACTIVITY_NO_HISTORY, Ti.Android.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS];
if (e.index === 0){
win.openIntent(intentData, flags);
}
});
dialog.show();
I hope it helps a bit...
I found a solution/workaround for my problem that the calendar permission was not asked for.
In the settings section of the device I removed the permissions by hand by the specific app. Now I did a reset on all settings of the installed app's and then the question is asked on the device when I start the particular part of the app.
Thus just remove the permissions and delete the app from the device is not enough!
I've used the part of code that I listed before, that from Jira.
So, for the moment my problem is solved (I think) and the app is asking for the needed permissions after first install.
Carlos, thanks for your comment, and I hope you can do something with my investigations too.

Android Marshmallow Permissions (MediaPicker/XLabs)

I've been working on an app, which incorporates XLabs Nuget packages - to be more specific, I'm using Xlabs in order to utilize cross-platform picture selection in Xamarin.Forms PCL project.
The app compiles without any problems, it works flawlessly on Kitkat, Lolipop and Marshmallow Xamarin Android Emulators.
Now, the problem arises when I export the app and try to run it on physical devices - Android 6.0+. It works without any issues on all Android devices (4.0-5.1) except on Marshmallow, where it hangs every time I try to use MediaPicker to select a Photo from image gallery (when I click on picture from the gallery).
The following asyc code never executes on Marshmallow devices:
private async Task SelectPicture()
{
Setup();
ImageSource = null;
try
{
var mediaFile = await _mediaPicker.SelectPhotoAsync(new CameraMediaStorageOptions
{
DefaultCamera = CameraDevice.Front,
MaxPixelDimension = 400
});
ImageSource = ImageSource.FromStream(() => mediaFile.Source);
}
catch (System.Exception ex)
{
Status = ex.Message;
}
}
And throws an error if I try tapping picture selection button again:
Only one operation can be active at a time
Again, the code Executes perfectly fine on anything below Android 6.0/Marshmallow.
At first I thought I was missing some SKDS and/or latest packages, however that wasn't the case and problem still is present.
Secondly, I have all the necessary permissions Enabled:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
However, now I'm starting to think that these defined permissions alone are not enough. Maybe I need give permission to access and write memory on code behind.
Any tips would be greatly appreciated.

IBM Worklight 6.0 - WL.Device.Geo.acquirePosition always return timeout

I'm building an application on worklight 6.0 and I'm trying to implement geolocation.
The method WL.Device.Geo.acquirePosition always returns
{"code":3,"message":"Position retrieval timed out."}
I followed these steps:
Created a new worklight project
Placed this code in my javascript file:
function wlCommonInit() {
WL.Device.Geo.acquirePosition(positive, negative, {
timeout : 30000,
enableHighAccuracy: true,
maximumAge:15000
});
}
function positive(data) {
WL.Logger.debug("bbbbbbbbbbb2" + JSON.stringify(data));
}
function negativa(data) {
WL.Logger.debug("aaaaaaaaaaaa" + JSON.stringify(data));
}
add an android environment
add these two permissions in AndroidManifest.xml:
uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
run the app on a samsung s2 with wifi and gps on
Is there anything that I'm missing?
I would also add to the AndroidManifest.xml the following:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
And make sure this is there as well:
<uses-feature android:name="android.hardware.wifi" />
Did you try with a higher timeout value?
See this post for more information.
Instead of doing:
navigator.geolocation.getCurrentPosition(win, fail, opts);
You can do this:
var geo = cordova.require('cordova/plugin/geolocation');
geo.getCurrentPosition(win, fail,opts);
Turns out you have to call the native module of Cordova to make this work without rebooting. You probably solved this or forgot, but may help other people.
I faced this issue also and it was because I was using the WL API before mobile device Geo was ready.
In my case I copied the code from google maps examples code and it initializes everything with:
google.maps.event.addDomListener(window, 'load', initializeMap)
And then in initializeMap() method is where I tried to use the WL.Device.Geo.acquirePosition method.
You must call the initializeMap method in the wlCommonInit() method, not in a "windows load event listener", this way the call to WL.Device.Geo.acquirePosition() will be done when the device GEO is ready.
Also check in Android check in settings -> Location services that you have enabled Use wireless networks and I have had to enable also Location and Google search...

navigator.geolocation.GetCurrentPosition throws “The last location provider was disabled” error

I am trying to create a very basic HTML5 page that grabs the geolocation, but I'm getting an error.
Here's what I have inside my 'script' tags:
function GetGeo() {
if (!navigator.geolocation) {
alert("Could not find geolocation");
}
else {
navigator.geolocation.getCurrentPosition(showMap, function (error) { alert("error encountered: " + error.message ); });
}
}
function showMap(position) {
window.alert(position.coords.latitude + ", " + position.coords.longitude);
}
The page just has a button on it, that calls the GetGeo() function.
What I did is dropped the .html file onto the SDCard of my phone. Then, I browsed to "content://com.android.htmlfileprovider/sdcard/GetGeo.html" and the page shows up correctly. When I click the button and execute, I get the following error: "The last location provider was disabled"
I have a couple questions:
1: Is it wrong to just drop the html file on the SDCard and try to run it there?
2: Is there something basic that I'm doing wrong that is not letting it get the geolocation from the mobile browser?
Thanks in advance for any help!
I figured this out: I needed to go into the setting of my mobile browser and check 'Enable Location'
It is also important to enable all the location sources from the Android Settings tab. Go to Settings, click on Location and Security. From here, make sure that the following are checked: (1) Use wireless networks, (2) Use GPS satellites, (3) Use sensor aiding.
Also make sure that the following permission is enabled in the manifest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Resources