Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19654] Android: Error accessing Camera on device below M

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionDuplicate
Resolution Date2015-10-08T02:40:32.000+0000
Affected Version/sRelease 5.1.0
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterAshraf Abu
AssigneeSrikanth Sombhatla
Created2015-10-01T05:12:28.000+0000
Updated2017-03-21T23:01:07.000+0000

Description

Running code:
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
});
Gives rise to log error:
10-01 13:07:22.718: E/TiExceptionHandler(27510): (main) [51,51] ----- Titanium Javascript Runtime Error -----
10-01 13:07:22.718: E/TiExceptionHandler(27510): (main) [0,51] - In app.js:1,16
10-01 13:07:22.718: E/TiExceptionHandler(27510): (main) [1,52] - Message: Uncaught Error: android.app.Activity.checkSelfPermission
10-01 13:07:22.718: E/TiExceptionHandler(27510): (main) [0,52] - Source: Titanium.Media.showCamera({
Due to https://github.com/appcelerator/titanium_mobile/blob/32600b01047b4654c92b341c6f0b61d38fa702b1/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java#L288 http://developer.android.com/reference/android/content/Context.html#checkSelfPermission(java.lang.String) Being only available in API Level 23 and above. More logs:
10-01 13:07:22.628: W/System.err(27510): java.lang.NoSuchMethodError: android.app.Activity.checkSelfPermission
10-01 13:07:22.628: W/System.err(27510): 	at ti.modules.titanium.media.MediaModule.hasPermissions(MediaModule.java:288)
10-01 13:07:22.628: W/System.err(27510): 	at ti.modules.titanium.media.MediaModule.showCamera(MediaModule.java:300)
10-01 13:07:22.628: W/System.err(27510): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
10-01 13:07:22.628: W/System.err(27510): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:177)
10-01 13:07:22.628: W/System.err(27510): 	at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:299)
10-01 13:07:22.628: W/System.err(27510): 	at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:203)
10-01 13:07:22.628: W/System.err(27510): 	at android.os.Handler.dispatchMessage(Handler.java:98)
10-01 13:07:22.628: W/System.err(27510): 	at android.os.Looper.loop(Looper.java:136)
10-01 13:07:22.628: W/System.err(27510): 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)

Comments

  1. Ashraf Abu 2015-10-01

    Need to check if API 23 and above for this part https://github.com/appcelerator/titanium_mobile/blob/32600b01047b4654c92b341c6f0b61d38fa702b1/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java#L300
  2. Srikanth Sombhatla 2015-10-01

    Tested with this code.
       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
       });
       
    PR https://github.com/appcelerator/titanium_mobile/pull/7258
  3. Ashraf Abu 2015-10-08

  4. Ashraf Abu 2015-10-08

    Resolving this as duplicate.
  5. Lee Morris 2017-03-21

    Closing ticket as duplicate with reference to the above comments.

JSON Source