如何使用 Ionic Framework 访问 Android 设备上的文件
How To Access Files on Android Device Using Ionic Framework
我正在学习使用 Cordova 相机的 Ionic 教程 API。
http://learn.ionicframework.com/formulas/cordova-camera/
据我所知,相机 API 功能一切正常,但我无法让我的图像显示回视图中。
我能够 return 文件 URI,但是当我尝试将其放入 ng-src
时,我在视图中什么也看不到。我假设 application/code 无法访问文件位置?
我的配置:
.config(function($stateProvider, $urlRouterProvider, $compileProvider) {
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|blob|content):|data:image\//);
...
我的控制器中的功能:
$scope.getPhoto = function() {
Camera.getPicture().then(function(imageURI) {
console.log(imageURI);
$scope.cameraPic = imageURI;
}, function(err) {
$scope.cameraPic = "error";
console.err(err);
});
};
我的看法:
<ion-view>
<ion-content>
<div class="form-group padding-top">
<button class='button button-positive' data-ng-click="getPhoto()">
Take Photo
</button>
</div>
<div class="item item-image">
<img ng-src="{{cameraPic}}"/>
</div>
{{cameraPic}}
</ion-content>
</ion-view>
这似乎是本教程推荐的方法,并且在 this thread. It sounds like it should work without using a Cordova file service implementation. I have found one such implementation 上也有重复,我想我可以使用,但是我在这里遗漏了什么吗?
编辑
使用 chrome://inspect/#devices,我能够查看 Webview/Console。我也重建了项目,只是为了看看是否有帮助。
绝对看起来像是本地文件访问问题。
事实证明,这是使用模拟器独有的问题。我终于在ngCordova项目上找到了以下内容:
NOTE: The camera API only works on a real device, and not in the
emulator.
来源:http://ngcordova.com/docs/plugins/camera/
这促使我使用 USB 调试器在实际设备上测试代码,其中文件由应用程序访问并按预期与视图共享。这应该被视为图书馆的一个怪癖。
我正在学习使用 Cordova 相机的 Ionic 教程 API。 http://learn.ionicframework.com/formulas/cordova-camera/
据我所知,相机 API 功能一切正常,但我无法让我的图像显示回视图中。
我能够 return 文件 URI,但是当我尝试将其放入 ng-src
时,我在视图中什么也看不到。我假设 application/code 无法访问文件位置?
我的配置:
.config(function($stateProvider, $urlRouterProvider, $compileProvider) {
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|blob|content):|data:image\//);
...
我的控制器中的功能:
$scope.getPhoto = function() {
Camera.getPicture().then(function(imageURI) {
console.log(imageURI);
$scope.cameraPic = imageURI;
}, function(err) {
$scope.cameraPic = "error";
console.err(err);
});
};
我的看法:
<ion-view>
<ion-content>
<div class="form-group padding-top">
<button class='button button-positive' data-ng-click="getPhoto()">
Take Photo
</button>
</div>
<div class="item item-image">
<img ng-src="{{cameraPic}}"/>
</div>
{{cameraPic}}
</ion-content>
</ion-view>
这似乎是本教程推荐的方法,并且在 this thread. It sounds like it should work without using a Cordova file service implementation. I have found one such implementation 上也有重复,我想我可以使用,但是我在这里遗漏了什么吗?
编辑
使用 chrome://inspect/#devices,我能够查看 Webview/Console。我也重建了项目,只是为了看看是否有帮助。
绝对看起来像是本地文件访问问题。
事实证明,这是使用模拟器独有的问题。我终于在ngCordova项目上找到了以下内容:
NOTE: The camera API only works on a real device, and not in the emulator.
来源:http://ngcordova.com/docs/plugins/camera/
这促使我使用 USB 调试器在实际设备上测试代码,其中文件由应用程序访问并按预期与视图共享。这应该被视为图书馆的一个怪癖。