我需要通过在intent extra中提供的路径创建一个图像文件来存根相机意图。浓缩咖啡只能用ActivityResult来回应。在哪里可以执行操作以从intent extra在传递路径创建文件。发射摄像机代码File destination = new File(Environment.getExternalStorageDirectory(), "app_name" + System.currentTimeMillis() + ".jpg");imageUri = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName() + ".fileprovider", destination); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); startActivityForResult(intent, AppConstants.REQUEST_CODE_CAMERA);试桩意图规范 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 您需要创建一个intentcallback来截取Uri值并在其中保存一个示例图像。科特林样品 intentCallback = IntentCallback { if (it.action == "android.media.action.IMAGE_CAPTURE") { it.extras.getParcelable<Uri>("output").run { val inStream = Resources.getResource(sampleImageFileName).openStream() val outStream = activity.contentResolver.openOutputStream(this) ByteStreams.copy(inStream, outStream) } } }您需要在intent触发器事件之前注册回调 IntentMonitorRegistry.getInstance().addIntentCallback(intentCallback)最后别忘了注销 IntentMonitorRegistry.getInstance().removeIntentCallback(intentCallback) (adsbygoogle = window.adsbygoogle || []).push({}); 07-24 09:28