Cordova Android Camera- 给出非法参数异常
Cordova Android Camera- giving illegal argument exception
我在 2 个月前开始使用 cordova Android 编程。一切都很好,主要是相机现在不工作了。但是上周我的项目目录是如何被删除的,我重新安装了 cordova 的所有插件和已编译的项目,但现在它在相机点击时显示错误 'illegal argument exception' 令人惊讶的是我没有更改单行代码并且它也可以正常工作在其他开发者机器上。
cordova插件添加cordova-plugin-camera
相机插件安装中使用的命令。
camera_app.js 文件
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}
// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
// largeImage.src = imageURI;
console.log(imageURI);
console.log(document_type);
}
function getPhoto(docType) {
// Retrieve image file location from specified source
document_type = docType
$('.docError').hide();
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
quality: 50,
destinationType: destinationType.FILE_URI
});
}
$('#file1').click(function() {
console.log('On camera click');
getPhoto("addressProof");
});
我尝试调试代码,最终发现这是由于提供程序路径引起的-
java.lang.IllegalArgumentException:缺少 android.support.FILE_PROVIDER_PATHS 元数据
但我已经在 Android xml 文件中添加了提供者路径元数据,因为它会在您添加 cordova 插件时自动添加。
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
</provider>
cordova 插件 -
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-camera 2.4.1 "Camera"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-whitelist 1.3.2 "Whitelist"
cordova-sqlite-存储 1.4.9 "Cordova sqlite storage plugin"
离子插件键盘 2.2.1 "Keyboard"
cordova平台-
已安装的平台:
android6.2.3
可用平台:
blackberry10 ~3.8.0(已弃用)
浏览器~4.1.0
webos ~3.7.0
windows~5.0.0
NPM 版本-
{ npm: '3.10.3',
战神:'1.10.1-DEV',
http_parser: '2.7.0',
icu: '57.1',
模块:'48',
节点:'6.4.0',
openssl: '1.0.2h',
紫外线:'1.9.1',
v8: '5.0.71.60',
zlib: '1.2.8' }
我今天遇到了类似的问题。尝试了一切(重新安装插件,从源代码重新安装插件,重新安装旧版本的插件)但似乎没有任何帮助。
不知道为什么但是之后
- 杀死模拟器
- >科尔多瓦干净android
-> cordova 平台移除 android
-> cordova 平台添加 android
->科尔多瓦构建android
- 连接我的设备
->科尔多瓦运行android
它又像以前一样工作了:-)
我仍然不知道为什么。
请自行承担风险。也许有帮助。
非常简单和基本。只需将下面的文件提供程序添加到您的 cordova 启动器 activity。在我的例子中,我有一些自定义 activity 并且错误地在所有 activity 的底部添加了提供者,我的猜测是 cordova 无法读取该提供者,这就是它给出的原因
java.lang.IllegalArgumentException:缺少 android.support.FILE_PROVIDER_PATHS 元数据
确保你的Android虚拟设备模拟器有前置和后置摄像头设置!
我也有同样的错误,删除和添加平台都不起作用。
Sidenote: For the Emulator to work, you need to have him already open and then you could run your Debug APK from Android Studio 3.3 or run `ionic cordova run android`.
有效方法:打开 Android 虚拟设备管理器(Android Studio -> 配置 -> AVD 管理器)
操作 -> 编辑(铅笔图标)
显示高级设置
确保您确实添加了前置和后置摄像头!在此设置之前是 "None",所以这不起作用,我得到了上面的错误。添加摄像头后,一切正常。
希望这对像我这样配置了 AVD 但没有摄像头的人有所帮助。
有两种方法可以解决这个问题。
可能与 AndroidManifest.xml (Package= / ApplicationId)
中的提供商名称不匹配
第二种方式在你的 build.gradle (app) 文件中
release {... minifyEnabled false ...}
在"CameraLancher.java"
中将applicationId改成app package id后生效
public void takePicture(int returnType, int encodingType)
{
// Save the number of images currently on disk for later
this.numPics = queryImgDB(whichContentStore()).getCount();
// Let's use the intent and see what happens
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Specify file so that large image is captured and returned
File photo = createCaptureFile(encodingType);
this.imageFilePath = photo.getAbsolutePath();
this.imageUri = FileProvider.getUriForFile(cordova.getActivity(),
"com.package-id" + ".cordova.plugin.camera.provider", ---->> your app package id
photo);
我在 2 个月前开始使用 cordova Android 编程。一切都很好,主要是相机现在不工作了。但是上周我的项目目录是如何被删除的,我重新安装了 cordova 的所有插件和已编译的项目,但现在它在相机点击时显示错误 'illegal argument exception' 令人惊讶的是我没有更改单行代码并且它也可以正常工作在其他开发者机器上。
cordova插件添加cordova-plugin-camera 相机插件安装中使用的命令。
camera_app.js 文件
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}
// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
// largeImage.src = imageURI;
console.log(imageURI);
console.log(document_type);
}
function getPhoto(docType) {
// Retrieve image file location from specified source
document_type = docType
$('.docError').hide();
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
quality: 50,
destinationType: destinationType.FILE_URI
});
}
$('#file1').click(function() {
console.log('On camera click');
getPhoto("addressProof");
});
我尝试调试代码,最终发现这是由于提供程序路径引起的- java.lang.IllegalArgumentException:缺少 android.support.FILE_PROVIDER_PATHS 元数据
但我已经在 Android xml 文件中添加了提供者路径元数据,因为它会在您添加 cordova 插件时自动添加。
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
</provider>
cordova 插件 -
cordova-plugin-app-version 0.1.9 "AppVersion" cordova-plugin-camera 2.4.1 "Camera" cordova-plugin-compat 1.1.0 "Compat" cordova-plugin-whitelist 1.3.2 "Whitelist" cordova-sqlite-存储 1.4.9 "Cordova sqlite storage plugin" 离子插件键盘 2.2.1 "Keyboard"
cordova平台-
已安装的平台: android6.2.3 可用平台: blackberry10 ~3.8.0(已弃用) 浏览器~4.1.0 webos ~3.7.0 windows~5.0.0
NPM 版本- { npm: '3.10.3', 战神:'1.10.1-DEV', http_parser: '2.7.0', icu: '57.1', 模块:'48', 节点:'6.4.0', openssl: '1.0.2h', 紫外线:'1.9.1', v8: '5.0.71.60', zlib: '1.2.8' }
我今天遇到了类似的问题。尝试了一切(重新安装插件,从源代码重新安装插件,重新安装旧版本的插件)但似乎没有任何帮助。 不知道为什么但是之后 - 杀死模拟器 - >科尔多瓦干净android -> cordova 平台移除 android -> cordova 平台添加 android ->科尔多瓦构建android - 连接我的设备 ->科尔多瓦运行android 它又像以前一样工作了:-) 我仍然不知道为什么。 请自行承担风险。也许有帮助。
非常简单和基本。只需将下面的文件提供程序添加到您的 cordova 启动器 activity。在我的例子中,我有一些自定义 activity 并且错误地在所有 activity 的底部添加了提供者,我的猜测是 cordova 无法读取该提供者,这就是它给出的原因 java.lang.IllegalArgumentException:缺少 android.support.FILE_PROVIDER_PATHS 元数据
确保你的Android虚拟设备模拟器有前置和后置摄像头设置! 我也有同样的错误,删除和添加平台都不起作用。
Sidenote: For the Emulator to work, you need to have him already open and then you could run your Debug APK from Android Studio 3.3 or run `ionic cordova run android`.
有效方法:打开 Android 虚拟设备管理器(Android Studio -> 配置 -> AVD 管理器)
操作 -> 编辑(铅笔图标)
显示高级设置
确保您确实添加了前置和后置摄像头!在此设置之前是 "None",所以这不起作用,我得到了上面的错误。添加摄像头后,一切正常。
希望这对像我这样配置了 AVD 但没有摄像头的人有所帮助。
有两种方法可以解决这个问题。
可能与 AndroidManifest.xml (Package= / ApplicationId)
中的提供商名称不匹配第二种方式在你的 build.gradle (app) 文件中
release {... minifyEnabled false ...}
在"CameraLancher.java"
中将applicationId改成app package id后生效public void takePicture(int returnType, int encodingType)
{
// Save the number of images currently on disk for later
this.numPics = queryImgDB(whichContentStore()).getCount();
// Let's use the intent and see what happens
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Specify file so that large image is captured and returned
File photo = createCaptureFile(encodingType);
this.imageFilePath = photo.getAbsolutePath();
this.imageUri = FileProvider.getUriForFile(cordova.getActivity(),
"com.package-id" + ".cordova.plugin.camera.provider", ---->> your app package id
photo);