var cameraOverlay = Titanium.UI.createView({});
var cameraOverlayButton = Titanium.UI.createView({
bottom: 10,
width: 100,
height: 100,
backgroundColor: "#f00"
});
cameraOverlay.add(cameraOverlayButton);
cameraOverlayButton.addEventListener('click', function(e) {
Ti.Media.takePicture();
});
function onOpen(argument) {
Titanium.Media.showCamera({
overlay: cameraOverlay,
showControls: false,
success: function(e) {
Ti.API.info('# SUCCESS : ' + JSON.stringify(e));
},
cancel: function(e) {
Ti.API.info('# CANCEL : ' + e.error);
},
error: function(e) {
Ti.API.info('# ERROR : ' + e.code + ' : ' + e.error);
},
mediaTypes: Ti.Media.MEDIA_TYPE_PHOTO,
});
}
$.index.addEventListener("open", onOpen);
$.index.open();
When using the latest SDK from the git (checkout 15th Sept.) and opening a camera with Ti.Media.showCamera() the app is crashing with
WARN] W/System.err: java.lang.NoSuchMethodError: No virtual method checkSelfPermission(Ljava/lang/String;)I in class Landroid/app/Activity; or its super classes (declaration of 'android.app.Activity' appears in /system/framework/framework.jar)
[WARN] W/System.err: at ti.modules.titanium.media.MediaModule.hasPermissions(MediaModule.java:288)
[WARN] W/System.err: at ti.modules.titanium.media.MediaModule.showCamera(MediaModule.java:300)
[WARN] W/System.err: at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
[WARN] W/System.err: at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:177)
[WARN] W/System.err: at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:299)
[WARN] W/System.err: at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:203)
[WARN] W/System.err: at android.os.Handler.dispatchMessage(Handler.java:98)
[WARN] W/System.err: at android.os.Looper.loop(Looper.java:135)
[WARN] W/System.err: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
[DEBUG] OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[DEBUG] Atlas: Validating map...
[ERROR] TiExceptionHandler: (main) [618,618] ----- Titanium Javascript Runtime Error -----
[ERROR] TiExceptionHandler: (main) [1,619] - In alloy/controllers/index.js:42,20
[ERROR] TiExceptionHandler: (main) [0,619] - Message: Uncaught Error: No virtual method checkSelfPermission(Ljava/lang/String;)I in class Landroid/app/Activity; or its super classes (declaration of 'android.app.Activity' appears in /system/framework/framework.jar)
[ERROR] TiExceptionHandler: (main) [0,619] - Source: Titanium.Media.showCamera({
[ERROR] V8Exception: Exception occurred at alloy/controllers/index.js:42: Uncaught Error: No virtual method checkSelfPermission(Ljava/lang/String;)I in class Landroid/app/Activity; or its super classes (declaration of 'android.app.Activity' appears in /system/framework/framework.jar)
On my phone I'm running 5.1.1 not beta 6 (marshmallow)
*Workaround*
Removing the checkSelfPermission() from hasPermissions() (MediaModule.java) will remove the error but probably won't be useful for Marshmallow.
Hello, We have tested this issue. Ti.Media.showCamera() works properly in my environment and app doesn't crash. *Testing Environment:* Appcelerator Studio, build: 4.3.0.201509031836 Appcelerator Command-Line Interface, version 5.0.1 Titanium SDK: 5.0.0GA Android Device: Nexus 7(android 5.1.1) *Steps to test* 1.Create an alloy project 2. Replace index.js with following code. 3. Run the project 4. When the app opens up, it will show the camera 5. Click to capture image And observe that app didn't crash and output is shown on the console *Test Case* index.js
*Output:*
Thanks.
Hello, We tested this issue but couldn't reproduce it as a bug in our environment. Ti.Media.showCamera() function is working as expected. *Console log:*
*Testing Environment:* Appcelerator Studio, build: 4.3.3.201510212245 Appcelerator Command-Line Interface, version 5.0.4 Mac Osx: 10.9.5 Ti sdk : 5.1.0.v20151113005238 Node.js Version : 0.12.7 Jdk: 1.7.0_65 Device: Nexus7(Android 5.1.1) *Steps to test* 1.Create an alloy project 2. Replace index.js with the following code. 3. Run the app 5. Click on the red button to capture image Observe that a success message is shown on console and app didn't crash. *Test Case:*
Thanks.
The problem was already fixed in another issue: https://github.com/appcelerator/titanium_mobile/pull/7394