简体   繁体   English

在Ionic App中显示设备存储中的图像

[英]Displaying image from device storage in Ionic App

I have image file on device in Android/data/myApp folder called test.jpg. 我在Android / data / myApp文件夹中的设备上有一个名为test.jpg的图像文件。 I want to display it in img tag. 我想在img标签中显示它。 I've tried every possible path in src attribute but nothing works. 我已经在src属性中尝试了所有可能的路径,但没有任何作用。 I've also tried change src to ng-src or data-ng-src. 我也尝试将src更改为ng-src或data-ng-src。 Nothing works and I am getting desperate. 什么都行不通,我变得绝望了。

The image is visible in storage when I look through windows explorer but it doesn't in my app. 当我浏览Windows资源管理器时,图像在存储中可见,但它不在我的应用程序中。 If I use $cordovaFile.checkFile function, everything looks perfect in the result data. 如果我使用$ cordovaFile.checkFile函数,结果数据中的一切看起来都很完美。 File exists, has nativeURL but still doesn't show in the view. 文件存在,具有nativeURL但仍未在视图中显示。

Anyone had this problem? 有人有这个问题吗? I've read everything google has to offer in this topic, but still without any progress on this issue. 我已经阅读了谷歌在这个主题中提供的所有内容,但在这个问题上仍然没有任何进展。 Can someone show me some simple example how to retrive image in Ionic app from device storage? 有人能告诉我一些简单的例子如何在设备存储中从Ionic应用程序中检索图像吗? What path should look like? 应该是什么样的路径? Maybe I have to add some permissions to my config.xml or andorid manifest? 也许我必须为config.xml或andorid清单添加一些权限? It's my first hybrid App. 这是我的第一个混合应用程序。 I don't have much experience in AngularJS/Cordova/Ionic. 我对AngularJS / Cordova / Ionic没有多少经验。

I've really stuck. 我真的卡住了。 Please help. 请帮忙。

Ok, so I guess I have to answer this question myself. 好的,所以我想我必须自己回答这个问题。 Everything works fine now when I use nativeURL of the file as src. 当我使用文件的nativeURL作为src时,一切正常。 I've added img-src: *; 我添加了img-src:*; to the content of http-equiv="Content-Security-Policy" meta tag in index but it still didn't work. 索引中的http-equiv =“Content-Security-Policy”元标记的内容但它仍然无法正常工作。 After 10th time restarting app suddenly everything was fine. 第10次重启应用程序突然一切都很好。 I still don't know if this was problem with meta tag but it work now so I am happy. 我仍然不知道这是不是meta标签的问题,但它现在工作,所以我很高兴。

If anyone want to see my config.xml, manifest or index just ask. 如果有人想看到我的config.xml,清单或索引只是问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM