Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27741] Android: Allow requestPermissions to succeed if already granted

GitHub Issuen/a
TypeImprovement
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2020-04-10T21:47:33.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.0.1
ComponentsAndroid
Labelsn/a
ReporterGary Mathews
AssigneeGary Mathews
Created2020-01-28T17:57:55.000+0000
Updated2020-06-18T12:16:18.000+0000

Description

Allow requestPermissions to succeed when when permissions have already been granted. This prevents the need for calling hasPermissions and simplified code. *EXAMPLE*
const overlay = Ti.UI.createView({});
const takePicture = Ti.UI.createButton({ title: 'Take Picture' });

takePicture.addEventListener('click', _ => {
    Ti.Media.takePicture();
});
overlay.add(takePicture);

// Should not need to call 'hasCameraPermissions', 'requestCameraPermissions' should succeed.
Ti.Media.requestCameraPermissions(e => {
    if (e.success) {
        Ti.Media.showCamera({
            success: e => {
                if (e.success) {
                    console.log('Taken picture successfully!');
                } else {
                    console.error(JSON.stringify(e, null, 2));
                }
            },
            saveToPhotoGallery: true,
            autohide: false,
            overlay: overlay,
            mediaTypes: [ Ti.Media.MEDIA_TYPE_PHOTO ]
        });
    }
});

Comments

  1. Gary Mathews 2020-02-25

    master: https://github.com/appcelerator/titanium_mobile/pull/11496
  2. Sohail Saddique 2020-03-23

    *FR: Pass* *Test Environment* SDK Ver: 8.3.1.GA & 9.0.0.GA & 9.1.0(this PR) OS Ver: 10.14.6 Appc NPM: 5.0.0 Appc CLI: 8.0.0 Daemon Ver: 3.2.0 Ti CLI Ver: 5.2.2 Node Ver: 10.17.0 Java Ver: 1.8.0_162 Devices: ⇨ Google Pixel 3a (Android 10) Emulators: Android 9 (API 28) and Android 10 (API 29) *Notes* * Permissions: WRITE_CALENDAR and WRITE_CONTACTS are required for Ti.Calendar and Ti.Contacts to execute correctly. * I also get these unnecessary warnings in the console as soon as the requests appear on-device (first-time launch):
       [WARN]  Calendar: (main) Calendar permissions are missing
       [WARN]  TiCommonContactsApi: (main) Contact permissions are missing
       
    Apart from these notes, the test case passes successfully with this PR.
  3. Gary Mathews 2020-03-24

    9_0_X: https://github.com/appcelerator/titanium_mobile/pull/11563
  4. Samir Mohammed 2020-04-01

    Reopening so 9_0_X back port can be tested.
  5. Samir Mohammed 2020-04-09

    FR Passed, Waiting on Jenkins build
  6. Christopher Williams 2020-04-09

    merged to master and 9_0_X
  7. Satyam Sekhri 2020-04-10

    Verified on: Mac OS: 10.15.4 SDK: 9.0.1.v20200409100807, 9.1.0.v20200409073825 Appc CLI: 8.0.0 JDK: 11.0.4 Node: 10.17.0 Studio: 6.0.0.202003132109 Device: Nexus4(v5.1.1) device, Pixel3(v10.0) emulator,

JSON Source