Titanium JIRA Archive
Appcelerator Community (AC)

[AC-423] showCamera - checkSelfPermission will crash on Nexus 4 (Android 5.1.1)

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionCannot Reproduce
Resolution Date2015-11-22T11:46:18.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsandroid, camera
ReporterMichael Gangolf
AssigneeMostafizur Rahman
Created2015-09-17T16:25:40.000+0000
Updated2015-11-22T13:34:46.000+0000

Description

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.

Comments

  1. Papia Chowdhury 2015-09-21

    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
       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(); 
       
    *Output:*
       [INFO] :   # SUCCESS : {"y":0,"x":0,"height":2592,"width":1944,"media":{"file":{"hidden":false,"nativePath":"file:///data/data/com.gsl.
       
    Thanks.
  2. Jebun Naher 2015-11-16

    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:*
       [INFO] :   # SUCCESS : {"y":0,"x":0,"height":2592,"width":1944,"media":{"file":{"hidden":false,"nativePath":"file:///data/data/com.gsl.newTest/app_appdata/tia1447669663928.jpg","writable":true,"executable":false,"parent":{"hidden":false,"nativePath":"file:///data/data/com.gsl.newTest/app_appdata","writable":true,"executable":false,"parent":{"hidden":false,"nativePath":"file:///data/data/com.gsl.newTest","writable":true,"executable":false,"parent":{"hidden":false,"nativePath":"file:///data/data","writable":false,"executable":false,"parent":{"hidden":false,"nativePath":"file:///data","writable":false,"executable":false,"parent":{"hidden":false,"nativePath":"file:///","writable":false,"executable":false,"parent":null,"readonly":true,"directoryListing":["firmware","persist","sdcard","storage","config","cache","acct","vendor","d","etc","tombstones","mnt","ueventd.rc","ueventd.flo.rc","system","sys","service_contexts","sepolicy","selinux_version","seapp_contexts","sbin","res","property_contexts","proc","init.zygote32.rc","init.usb.rc","init.trace.rc","init.rc","init.flo.usb.rc","init.flo.rc","init.flo.diag.rc","init.environ.rc","init","fstab.flo","file_contexts","default.prop","data","charger","root","dev"],"size":0,"apiName":"Ti.Proxy","name":"","symbolicLink":false,"bubbleParent":true},"readonly":false,"directoryListing":[],"size":4096,"apiName":"Ti.Proxy","name":"data","symbolicLink":false,"bubbleParent":true},"readonly":false,"directoryListing":[],"size":8192,"apiName":"Ti.Proxy","name":"data","symbolicLink":false,"bubbleParent":true},"readonly":false,"directoryListing":["lib","cache","databases","app_appdata"],"size":4096,"apiName":"Ti.Proxy","name":"com.gsl.newTest","symbolicLink":false,"bubbleParent":true},"readonly":false,"directoryListing":["tia1447669663928.jpg"],"size":4096,"apiName":"Ti.Proxy","name":"app_appdata","symbolicLink":false,"bubbleParent":true},"readonly":false,"directoryListing":[],"size":236024,"apiName":"Ti.Proxy","name":"tia1447669663928.jpg","symbolicLink":false,"bubbleParent":true},"nativePath":"file:///data/data/com.gsl.newTest/app_appdata/tia1447669663928.jpg","height":2592,"length":236024,"width":1944,"mimeType":"image/jpeg","apiName":"Ti.Blob","text":null,"type":1,"bubbleParent":true},"mediaType":"public.image","code":0,"cropRect":{"height":2592,"width":1944,"y":0,"x":0},"success":true}
       [INFO] :   APSAnalyticsService: Stopping Analytics Service
       
    *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:*
       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();
       
    Thanks.
  3. Michael Gangolf 2015-11-22

    The problem was already fixed in another issue: https://github.com/appcelerator/titanium_mobile/pull/7394

JSON Source