navigator.camera.getPicture 在 android 中不起作用
Posted
技术标签:
【中文标题】navigator.camera.getPicture 在 android 中不起作用【英文标题】:navigator.camera.getPicture not working in android 【发布时间】:2017-08-03 11:48:59 【问题描述】:我正在使用 Cordova 和 Worklight 6.3 开发应用程序,但在使用 camera.getPicture 函数时遇到问题。
请检查下面的相机代码 sn-p。
var cameraOptions =
quality: 50,
targetWidth: 720,
targetHeight: 600,
encodingType: Camera.EncodingType.JPEG,
destinationType: Camera.DestinationType.DATA_URL,
correctOrientation: true,
sourceType: Camera.PictureSourceType.CAMERA
;
android 错误日志:
08-04 12:43:26.727: E/PluginManager(1168): Uncaught exception from plugin
08-04 12:43:26.727: E/PluginManager(1168): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
08-04 12:43:26.727: E/PluginManager(1168): at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:560)
08-04 12:43:26.727: E/PluginManager(1168): at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:534)
08-04 12:43:26.727: E/PluginManager(1168): at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:376)
08-04 12:43:26.727: E/PluginManager(1168): at cordova.camera.CameraLauncher.takePicture(CameraLauncher.java:302)
08-04 12:43:26.727: E/PluginManager(1168): at cordova.camera.CameraLauncher.callTakePicture(CameraLauncher.java:276)
08-04 12:43:26.727: E/PluginManager(1168): at cordova.camera.CameraLauncher.execute(CameraLauncher.java:185)
08-04 12:43:26.727: E/PluginManager(1168): at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:86)
08-04 12:43:26.727: E/PluginManager(1168): at org.apache.cordova.PluginManager.exec(PluginManager.java:153)
08-04 12:43:26.727: E/PluginManager(1168): at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:61)
08-04 12:43:26.727: E/PluginManager(1168): at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:40)
08-04 12:43:26.727: E/PluginManager(1168): at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
08-04 12:43:26.727: E/PluginManager(1168): at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:39)
08-04 12:43:26.727: E/PluginManager(1168): at android.os.Handler.dispatchMessage(Handler.java:102)
08-04 12:43:26.727: E/PluginManager(1168): at android.os.Looper.loop(Looper.java:148)
08-04 12:43:26.727: E/PluginManager(1168): at android.os.HandlerThread.run(HandlerThread.java:61)
我关注 ibm Fix 但同样的错误 https://www.ibm.com/support/knowledgecenter/SSHS8R_6.3.0/com.ibm.worklight.dev.doc/dev/t_android_cam_api_24.html
AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="$applicationId.fileprovider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
【问题讨论】:
该问题是否特定于某个 Android 版本? 请看:How do I avoid misusing tags? Vinin K,我用几个版本测试了同样的问题:/ 在您的 AndroidManifest.xml 中,这行似乎被错误地引用了 - android:authorities="$applicationId.fileprovider"。您能否将其更改为 android:authorities="$applicationId.fileprovider" 并尝试更新给我们? 【参考方案1】:在 default.xml 中添加以下行
<preference name="applicationId" value="com.APPlol.test" />
// ID in widget is the value
<widget id="com.APPlol.test"></widget> // in config .xml
【讨论】:
以上是关于navigator.camera.getPicture 在 android 中不起作用的主要内容,如果未能解决你的问题,请参考以下文章