我在 AdvancedLayout 示例项目中的相机操作有问题。我正在将以下代码添加到从索尼下载的 sdk 中的示例项目 AdvancedLayout 中。我在这里遵循相机指南https://developer.sony.com/develop/wearables/smarteyeglass-sdk/guides/camera/ 请注意,它适用于模拟器,但不适用于真实设备,并且该指南缺少 startCamera 和 stopCamera 操作我将自己添加到我认为合适的地方。
AndroidManifest.xml 里面
<uses-permission android:name="com.sony.smarteyeglass.permission.CAMERA" />
在 AdvancedLayoutControls.java 中
添加以下类和字段
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();
}
}
在 AdvancedLayoutsControl.java 中
将以下代码添加到 AdvancedLayoutsControl 构造函数
utils = new SmartEyeglassControlUtils(hostAppPackageName, mSmartEyeglassEventListener);
并且在 AdvancedLayoutsControl.java 中也添加了这个覆盖函数。当用户处于 SampleDetail(第二级)视图时,希望它在 LongPress 上拍照。
@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);
}