我在不同的应用程序中使用了类似的代码,但这次我仍然遇到了问题。在调用 startActivityForResult(CamIntent, Integer.parseInt(code)); 相机打开,但是当我单击图像时没有任何反应,它会一直单击图像,但不会显示带有刻度和十字图标的图像页面。
在清单文件中
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
@xml/文件路径
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="." />
</paths>
活动中的代码
public void ClickImageFromCamera(String code) {
Intent CamIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File destination = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis() + ".jpg");
Log.e("img fromCam", String.valueOf(destination));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = FileProvider.getUriForFile(Objects.requireNonNull(getApplicationContext()),
BuildConfig.APPLICATION_ID + ".fileprovider", destination);
Log.e("img uri", String.valueOf(uri));
CamIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
} else {
uri = Uri.fromFile(destination);
CamIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
}
CamIntent.putExtra("return-data", true);
startActivityForResult(CamIntent, Integer.parseInt(code));
}
日志
D/CompatibilityChangeReporter: Compat change id reported: 147798919; UID 10625; state: DISABLED
D/OpenGLRenderer: endAllActiveAnimators on 0x76e3d22fc0 (AlertController$RecycleListView) with handle 0x7603cc4890
E/img fromCam: /storage/emulated/0/1611230389449.jpg
E/img uri: content://com.example.aps.fileprovider/external_files/1611230389449.jpg
E/Request code: 0 (when I click back)
E/ResultCode: 0