Android pm出现错误,android - FileProvider错误,尝试调用虚拟方法'android.content.res.XmlResourceParser android.conte...

我想打开相机并从中拍照以将其上传到服务器。 但是,每次我尝试打开相机时,应用程序崩溃都会显示上述错误,我尝试了多种解决方案,但它们对我都不起作用。 我的代码如下:

我的包裹名称是

lc.android.gauge

并且应用程序ID为

com.test.gauge

授予权限后,我调用此方法

private void dispatchTakePictureIntent() {

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) {

// Error occurred while creating the File

}

// Continue only if the File was successfully created

try {

if (photoFile != null) {

Uri photoURI = FileProvider.getUriForFile(this,

"com.test.gauge.fileprovider",

file);

takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);

startActivityForResult(takePictureIntent, 0);

}

} catch (Exception e) {

Log.e("imageException", e.toString());

}

}

}

在上述方法中,应用程序在此行崩溃

Uri photoURI = FileProvider.getUriForFile(this,"com.test.gauge.fileprovider",file);

createImageFile()方法

private File createImageFile() throws IOException {

// Create an image file name

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());

String imageFileName = "JPEG_" + timeStamp + "_";

File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);

File image = File.createTempFile(

imageFileName, /* prefix */

".jpg", /* suffix */

storageDir /* directory */

);

// Save a file: path for use with ACTION_VIEW intents

mCurrentPhotoPath = image.getAbsolutePath();

return image;

}

内部清单标签

android:name="android.hardware.camera"

android:required="true" />

内部应用程序标签

android:name="android.support.v4.content.FileProvider"

android:authorities="lc.android.gauge.fileprovider"

android:exported="false"

android:grantUriPermissions="true">

android:name="android.support.FILE_PROVIDER_PATHS"

android:resource="@xml/file_paths" />

file_paths xml

name="my_images"

path="Android/data/com.test.gauge/files/Pictures" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值