Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6489] Android: Ti.Media.hasCameraPermissions() not working as expected

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterMuhammad Ahmed Fahad
AssigneeYordan Banev
Created2020-02-13T03:29:03.000+0000
Updated2020-02-17T15:51:37.000+0000

Description

Ti.Media.hasCameraPermissions() return false even though Camera Permission has been enabled. Tested using Samsung Galaxy Note8 running on Android 9.0 and Titanium SDK: 9.0.0.v20200211122336 Also tested on Google Nexus 5X running on Android 8.1.0 Testing: Enable Camera permissions of the app by toggling switch in App Settings Menu
$.addListener($.button, 'click', function () {
  alert("Ti.Media.hasCameraPermissions(): " + Ti.Media.hasCameraPermissions());
}); 

Comments

  1. Muhammad Ahmed Fahad 2020-02-13

    Please look into this issue as soon as possible. This seems to be the only issue following our upgrade to 9.0.0 version of the titanium SDK
  2. Ewan Harris 2020-02-13

    [~fahad86] Does the following look similar to your code for the full flow of permissions? I'm seeing the same behaviour as you're describing on 8.3.1.GA and 9.0.0, but only if I don't have <uses-permission android:name="android.permission.CAMERA" /> in my tiapp. I am able to grant permissions for the gallery, but not for the camera, so Ti.Media.hasCameraPermissions() returns false (correctly). Adding that permission to the tiapp will allow me to be prompted for camera permissions, and then Ti.Media.hasCameraPermissions() returns true. Additionally, if I only approve the camera permission and not the storage permission then Ti.Media.hasCameraPermissions() will return false for both 8.3.1.GA and 9.0.0
       var win = Ti.UI.createWindow({});
       var lbl = Ti.UI.createLabel({
           text: 'click1',
           top: 200
       });
       var lbl2 = Ti.UI.createLabel({
           text: 'click2',
           top: 300
       });
       lbl.addEventListener('click', () => {
           Ti.Media.requestCameraPermissions((e) => {
               console.log(e);
           });
       });
       lbl2.addEventListener('click', () => {
           alert("Ti.Media.hasCameraPermissions(): " + Ti.Media.hasCameraPermissions());
       });
       win.add(lbl);
       win.add(lbl2);
       win.open();
       
  3. Muhammad Ahmed Fahad 2020-02-14

    Already had the permission: Also accepted the Media Storage access. But issue gets fixed only after adding: This wasn't the case with 8.3.1. Had the attribute: android:maxSdkVersion="18" on the WRITE_EXTERNAL_STORAGE permission and it was working till 8.3.1. But removed the attribute now and all ok.
  4. Yordan Banev 2020-02-17

    [~fahad86] Since Titanium 8.0.0.GA the minimum Android version required is 19, meaning that the addition of android:maxSdkVersion="18" will not have effect. As for why it was causing the error - Google recently fixed an error on their end that was causing a single permission to grant all the permissions of a group, so explicitly marking the WRITE_EXTERNAL_STORAGE for API levels up to 18 would mess up the expected permissions for external storage. That being said I was not able to reproduce the issue against the current master version of Titanium (9.1.0) without having the WRITE_EXTERNAL_STORAGE added in tiapp.xml If I got it right you had such a scenario? If you are able to share the android segment of the reproduceable case it will be much easier to find a possible issue.

JSON Source