0

I made a website and turned it into Android app, using Phonegap website. I have files stored on a local storage on ASUS TF300 tablet, and I need an app to access them. To access the files I use links like that:

file:///sdcard/original_img/3_1_5.jpg

Now the funny part. If I open this link in Chrome, Firefox or any other browser on my tablet - the image loads up. But if I launch an app with the same link in its index.html, the image doesn't load at all.

What could it be? Is a storage path somehow different for the apps and for browsers?

Nebular Dust
  • 403
  • 1
  • 6
  • 17
  • Also, if I just copy the folder to tablet and open index.html using Chrome - all files load as needed. It looks like PhoneGap does something to my links or something, I don't know. – Nebular Dust Sep 02 '16 at 04:45

2 Answers2

1

Looks like you need to add this into your app AndroidManifest.xml :

<manifest ...>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     ...
 </manifest>

UPDATE from chat conversation (based on this thread) :

Add config.xml:

<preference name="AndroidPersistentFileLocation" value="Compatibility" /> 
<preference name="AndroidExtraFilesystems" value="sdcard,cache" />

file pathes should be like following:

 file:///sdcard/<path>
Community
  • 1
  • 1
j2ko
  • 2,479
  • 1
  • 16
  • 29
  • I will try it tomorrow and let you know if it works. – Nebular Dust Sep 02 '16 at 07:01
  • Ok, I tried opening the .apk file with WinRAR and editing AndroidManifest.xml. But there are only numbers inside of it, looks like some kind of hex code or something. Do I just paste this line you mentioned below those numbers? It's confusing. – Nebular Dust Sep 06 '16 at 20:33
  • Check this [thread](http://stackoverflow.com/questions/27876730/how-to-set-permissions-for-android-using-phonegap-build). If your config file correct then maybe the problem not with android part - but in your website itself. – j2ko Sep 06 '16 at 20:38
  • No, my website works perfectly when I upload it to tablet and open it locally in any browser - all images and links work. Only apk version doesn't work. It's pretty clear that something prevents links from accessing files when they are in apk, but it all works fine in a browser. – Nebular Dust Sep 06 '16 at 20:40
  • Did you try to acces file like so 'cdvfile://localhost/sdcard/ – j2ko Sep 06 '16 at 20:58
  • I'm trying apktool comiling/decompiling manifest now, maybe it will work. And no, I didn't try that. – Nebular Dust Sep 06 '16 at 21:04
  • here is post about accessing external file from cordova : [(LINK)](http://stackoverflow.com/questions/22868089/how-to-access-external-storage-with-cordova-file-file-system-roots-plugins) – j2ko Sep 06 '16 at 21:06
  • Since you are here, can I ask you. So when he mentions adding something as JavaScript, where should it go? To any JS file that I use on my website? – Nebular Dust Sep 06 '16 at 21:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/122778/discussion-between-j2ko-and-nebular-dust). – j2ko Sep 06 '16 at 21:13
0

if you are using the above procedure You might need to allow th access with this line :

mWebView.getSettings().setAllowFileAccess(true);

Or try using this alternatives (in html )

String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file:/"+ base + "/original_img/3_1_5.jpg";
String strimg="<img src=\""+ imagePath + "\" alt=\"\" width=\"168\" height=\"120\" v:shapes=\Picture_x0020_421\" />";
Thecarisma
  • 1,424
  • 18
  • 19
  • Where exactly do I add this line "mWebView.getSettings().setAllowFileAccess(true);" in phonegap online app builder? – Nebular Dust Sep 02 '16 at 04:56
  • 2500 0000 0301 1000 1800 0000 2a00 0000 ffff ffff ffff ffff 2400 0000 0301 1000 That's what I get in manifest file inside .apk, lines and lines of these numbers. Do I just add your code to the numbers? – Nebular Dust Sep 06 '16 at 20:44