[TIMOB-19654] Android: Error accessing Camera on device below M
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2015-10-08T02:40:32.000+0000 |
Affected Version/s | Release 5.1.0 |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Ashraf Abu |
Assignee | Srikanth Sombhatla |
Created | 2015-10-01T05:12:28.000+0000 |
Updated | 2017-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)
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
Tested with this code.
PR https://github.com/appcelerator/titanium_mobile/pull/7258
Resolving this as duplicate.
Closing ticket as duplicate with reference to the above comments.