Problems with camera operations inside Advanced Layouts

123 Views Asked by At

I am having problems with the camera operations inside AdvancedLayout sample project. I am adding following code to the sample project AdvancedLayout in the sdk downloaded from sony. I am following the Camera guide here https://developer.sony.com/develop/wearables/smarteyeglass-sdk/guides/camera/ Note that it works in emulator but not in real device and the guide is missing startCamera and stopCamera operations that I added myself to places I thought that it would fit.

inside AndroidManifest.xml

<uses-permission android:name="com.sony.smarteyeglass.permission.CAMERA" /> 

inside AdvancedLayoutControls.java

adding following class and field

private final SmartEyeglassEventListener mSmartEyeglassEventListener = new MySmartEyeglassEventListener();
        class MySmartEyeglassEventListener extends SmartEyeglassEventListener {
            @Override
            public void onCameraReceived(CameraEvent event) {
                Log.d(Constants.LOG_TAG, "onCameraReceived");
                utils.stopCamera();
            }
            @Override
            public void onCameraErrorReceived(int error) {
                Log.d(Constants.LOG_TAG, "onCameraErrorReceived");
                utils.stopCamera();
            }
            @Override
            public void onCameraReceivedFile(String filePath) {
                Log.d(Constants.LOG_TAG, "onCameraReceivedFile " + filePath);
                utils.stopCamera();
            }
            @Override
            public void onRecordingStatus(long timeInMs, long frames) {
                Log.d(Constants.LOG_TAG, "onRecordingStatus");
                utils.stopCamera();
            }
        }

inside AdvancedLayoutsControl.java

adding following code to AdvancedLayoutsControl constructor

utils = new SmartEyeglassControlUtils(hostAppPackageName, mSmartEyeglassEventListener);

and inside AdvancedLayoutsControl.java adding this override function as well. Want it to take picture on LongPress when user is in SampleDetail (2nd level) view.

@Override
    public void onTouch(ControlTouchEvent event) {      
        if(event.getAction() == Intents.TOUCH_ACTION_LONGPRESS) {
            File folder = new File(Environment.getExternalStorageDirectory(), "myfile");
            folder.mkdir();
            Date now = new Date();

            File file =  new File(folder, now.getYear() + "" + now.getMonth() + "" + now.getDate() + "" + now.getHours() + "" + now.getMinutes() + "" + now.getSeconds() + "savefile.jpg");
            try {
                utils.startCamera(file.getAbsolutePath());
            } catch (ControlCameraException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            utils.setCameraMode(SmartEyeglassControl.Intents.CAMERA_JPEG_QUALITY_STANDARD, SmartEyeglassControl.Intents.CAMERA_RESOLUTION_1M, SmartEyeglassControl.Intents.CAMERA_MODE_STILL_TO_FILE);
            utils.requestCameraCapture();
        }
        super.onTouch(event);
    }
1

There are 1 best solutions below

1
On BEST ANSWER

You need to call setCameraMode before startCamera. Because it initializes camera with those preferences.

I only changed that part in your code and used the rest as you provided. Then I tested both on the device and the emulator. It works without any problem when you move setCameraMode call above startCamera.