拍摄图像时如何获得设备的取向角度?

时间:2018-09-22 12:41:44

标签: android android-camera android-sensors

我正在编写一个使用手机摄像头和传感器在空间上匹配照片的应用程序。
我正在使用相机意图拍照:

private void cameraIntent() {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // Ensure that there's a camera activity to handle the intent
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            // Create the File where the photo should go
            File photoFile = null;
            try {
                photoFile = createImageFile();
            } catch (IOException ex) {
                Toast.makeText(getApplicationContext(),ex.getMessage(),Toast.LENGTH_LONG).show();
            }
            // Continue only if the File was successfully created
            if (photoFile != null) {
                Uri photoURI = FileProvider.getUriForFile(this,
                        "com.example.android.fileprovider",
                        photoFile);
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
            }
        }
    }

问题是,我希望能够在拍摄图像后立即保存设备的加速度计和磁力计传感器读数(对于SensorManager.getRotationMatrix)。
在网上搜索时,我能找到的最接近的东西是将GPS参数保存在onActivityResult中,但这没什么用,因为用户可能在拍照并点击确定后才移动了手机。
有什么方法可以使手机在捕获过程中运行少量代码以记录传感器的数据?

先谢谢了。

0 个答案:

没有答案