Image 保存相机图像时遇到问题

Image 保存相机图像时遇到问题,image,camera,save,Image,Camera,Save,我已经浏览了内容,似乎找不到我问题的答案。 我的应用程序中有一个图像文件和一个按钮。。。我正在关注android开发者的教程,但在保存文件时遇到了问题。有一次,我可以保存到缓存,但我宁愿保存到图片文件夹中。 这是我的密码 static final int REQUEST_IMAGE_CAPTURE = 1; private void dispatchTakePictureIntent() { Intent dispatchTakePictureIntent =

我已经浏览了内容,似乎找不到我问题的答案。
我的应用程序中有一个图像文件和一个按钮。。。我正在关注android开发者的教程,但在保存文件时遇到了问题。有一次,我可以保存到缓存,但我宁愿保存到图片文件夹中。 这是我的密码

    static final int REQUEST_IMAGE_CAPTURE = 1;

    private void dispatchTakePictureIntent() {

        Intent dispatchTakePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // Ensure that there's a camera activity to handle the intent
        if (dispatchTakePictureIntent.resolveActivity(getPackageManager()) != null) {
            // Create the File where the photo should go
            File photoFile = null;
            photoFile = createImageFile();
            // Continue only if the File was successfully created
            if (photoFile != null) {
                Uri photoURI = FileProvider.getUriForFile(this,
                        "com.example.ConfinedSpaceManagement",
                        photoFile);
                dispatchTakePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(dispatchTakePictureIntent, REQUEST_TAKE_PHOTO);
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");
            imageView.setImageBitmap(imageBitmap);

        }
    }

    String currentPhotoPath;

    private File createImageFile(){
        // Create an image file name
        File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        if (!storageDir.exists()) {
            if (!storageDir.mkdirs()) {
                Log.d("Confined_Space", "failed to create Directory");
                return null;
            }
        }
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        return new File(storageDir.getPath() + File.separator + "ConSp" + timeStamp + ".jpg");
    }
    //String imageFileName = "JPEG_" + timeStamp + "_";
    ////////////////////////////////////////////////////////////////
    static final int REQUEST_TAKE_PHOTO = 1;
}
这是我的舱单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.confinedspacemanagement">

    <uses-feature android:name="android.hardware.camera"
        android:required="false" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="18" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.google.android.actions"
            android:resource="@xml/file_paths" />

        <activity android:name=".Signature" />
        <activity android:name=".AuditWork" />
        <activity android:name=".DisplayIndividual" />
        <activity android:name=".SecondActivity" />
        <activity android:name=".Definition" />
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

      <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.example.confinedspacemanagement.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"/>
        </provider>
    </application>

</manifest>

这是我的xml.file\u路径

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="my_images" path="Android/data/com.example.package.name/files/Pictures" />
</paths>

该活动是一个sqlite表单页面。我正在尝试拍摄一张照片,将其保存到指定的文件中,然后将文件路径保存到数据库中

有人帮忙吗???我应该使用camera2吗?

我在PRABEESH R K先生的网站上找到了答案

图片保存得很好,但我是从一个不是主要活动的活动中拍摄的。当我返回结果时,页面返回到主活动,而不是最初请求相机的页面。有没有办法把它放在发送页面上