Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19422] Android M: App crashes if using camera in device due to permissions

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2015-09-07T05:06:21.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.1.0
ComponentsAndroid
Labelscamera, permissions
ReporterChee Kiat Ng
AssigneeHieu Pham
Created2015-08-28T04:13:16.000+0000
Updated2015-10-27T01:03:33.000+0000

Description

The problem is, the app doesn't prompt the user for permissions, and even if the permissions are set, the app crashes.

Steps to reproduce:

1. Use the sample app 2. ti build 3. it will show an error 4. Go to settings permissions, set the app permission such that storage = YES, camera = NO 5. App will crash *Note* if both permissions are set to YES MANUALLY like (4.), the app works.
Titanium.Media.showCamera({
	success:function(event) {
		// called when media returned from the camera
		Ti.API.debug('Our type was: '+event.mediaType);
		if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
			var imageView = Ti.UI.createImageView({
				width:win.width,
				height:win.height,
				image:event.media
			});
			win.add(imageView);
		} else {
			alert("got the wrong type back ="+event.mediaType);
		}
	},
	cancel:function() {
		// called when user cancels taking a picture
	},
	error:function(error) {
		// called when there's an error
		var a = Titanium.UI.createAlertDialog({title:'Camera'});
		a.setMessage(JSON.stringify(error));
		a.show();
	},
	saveToPhotoGallery:true
});

Comments

  1. Chee Kiat Ng 2015-08-28

  2. Ashraf Abu 2015-08-31

    Useful commands for testing:- From terminal, to grant permission instead of going to Settings in phone.
       adb shell pm grant com.titanium.test android.permission.CAMERA
       
    From terminal, to revoke permission instead of going to Settings in phone.
       adb shell pm revoke com.titanium.test android.permission.CAMERA
       
  3. Hieu Pham 2015-09-04

    master PR: https://github.com/appcelerator/titanium_mobile/pull/7125. This PR check permissions and exit gracefully (no-op) if permission is not granted.
  4. Ashraf Abu 2015-09-07

    Master PR and backport pr merged.
  5. Ashraf Abu 2015-09-08

    5_0_X revert https://github.com/appcelerator/titanium_mobile/pull/7149
  6. Ben Bahrenburg 2015-09-14

    Is still broken in the latest version from master. version: 5.1.0 git hash: ae65d5dd2d48289604d29d4be25607acfa1eab80 jenkins: Job #4515 parity: parity repor
  7. Ashraf Abu 2015-09-14

  8. Ben Bahrenburg 2015-09-14

    Confirmed 5.0.0.v20150911123911 is working. Will test master once it goes through the build cycle.
  9. Ashraf Abu 2015-09-14

    [~ben.bahrenburg@gmail.com] Thanks!
  10. Lokesh Choudhary 2015-10-27

    Verified the fix. The app does not crash but, 1. If filesystem permission is granted & camera permission not granted. The app does nothing. 2. If camera permission is granted & filesystem permission not granted. The app does nothing. 3. If both the permissions are granted the app performs as normal. Closing Environment: Appc Studio : 4.4.0.201510231805 Ti SDK : 5.1.0.v20151022152020 Ti CLI : 5.0.5 Alloy : 1.7.18 MAC Yosemite : 10.10.5 Appc NPM : 4.2.1-6 Appc CLI : 5.1.0-38 Node: v0.10.37 Nexus 5 - Android 6.0

JSON Source