Luc*_*cas 3 android cordova cordova-plugins ngcordova
我使用 Apache Cordova 实现了一个应用程序,并使用了 $cordovaCamera 插件。当 $cordovaCamera 的源类型是 Camera.PictureSourceType.PHOTOLARY 时,输出类似于
“内容://com.android.providers.media.documents/document/image”
并且,当我使用 Camera.PictureSourceType.CAMERA 时,我得到
“file:///storage/emulated/0/Android/data/com.ionic.viewapp/cache/image.jpg”。
在我的情况下,格式“file://..”更有用。
是否可以从内容 URI 中获取文件 URI?
我找到了这个问题的很多答案,但所有解决方案都是针对 JAVA,而不是针对 Javascript。
我发现了问题。我正在使用 Ionic 和 Ionic View 在设备中进行测试。
当我尝试cordova-plugin-filepath 时,它不起作用。但我发现问题是在 Ionic View 这个插件失败了。
所以,我在一个服务中写了这个函数:
// data is the return of $cordovaCamera.getPicture.
getFilePath: function(data){
var deferred = $q.defer();
window.FilePath.resolveNativePath(data, function(result) {
deferred.resolve('file://' + result;);
}, function (error) {
throw new Error("");
});
return deferred.promise;
}
Run Code Online (Sandbox Code Playgroud)
返回我需要的文件 URI。然后,我在手机中安装了apk,它可以工作。现在,我可以存储从相机或画廊获得的图像并上传到服务器。
| 归档时间: |
|
| 查看次数: |
6372 次 |
| 最近记录: |