Discussion Forums  >  Images, Documents, File Locations

Replies: 9    Views: 263

piggilypoo
Aspiring developer
Profile
Posts: 172
Reg: Jun 28, 2011
San Diego
5,120
06/26/13 03:59 PM (11 years ago)

Possible to have local paths on iOS and Android in same app?

Ok so I have a working android app, and in a customHTML screen I have an image loading via file:///android_assets/BT_Docs/image.jpg This causes the image to display fine for android. However, for obvious reasons, this file path won't work when the same app is opened up in xCode. Is there a way to have a local file path that works across both? Or will I have to make an entirely new app just for the iPhone version?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
06/26/13 04:08 PM (11 years ago)
Well, keep in mind iOS actually doesn't care 'where' the resource is located; all those directories and things are for us humans to distinguish. Android cares quite a bit. Also keep in mind HTML calls on it's resources in a 'relative to the document' fashion. So, if you 'add' an image to the BT_images directory in the required fashion, and your HTML page calls for an image by <imgsrc="..\BT_images\myimage.png"> it probably still won't find it, because although that 'looks' like the directory structure, it isn't always the case. Your best bet would be to 'add' the images into your BT_docs directory, so that the HTML file can find them easily. 'AFTER' the image has been 'added' to the BT_docs, you can move them within xcode to wherever you want...Physically they'll still be in your BT_Docs, but Xcode can keep track of it. But HTML will not, so as long as it 'physically' remains in BT_Docs, you're good. Does this help? Cheers! -- Smug
 
piggilypoo
Aspiring developer
Profile
Posts: 172
Reg: Jun 28, 2011
San Diego
5,120
like
06/26/13 04:59 PM (11 years ago)
I'm not sure this helps. The issue is, in my customHTML screen, I call an image via img src="file:///android_assets/BT_Docs/image.jpg" Which displays the local image fine on android. However, there is no such path "file:///android_assets/BT_Docs/image.jpg" on iphone, so when the same app is run in xCode, the images don't display. I can get the images to display in xCode if I change the path to "image.jpg", but then this breaks the Android app and the images don't display in android. So what I'm asking, is if there is a way to display local images on both platforms, instead of having to remake the entire app just so I can have separate file paths.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
06/26/13 05:08 PM (11 years ago)
well, the 'easiest' thing would be to use the same directory for both the html and the images... <imgsrc="./myimage.jpg> and in Xcode, keep it all in BT_Docs, and in Android, keep it all in BT_Docs. remembering that if you do it this way, the Android system won't know the images are there, but if you're only using them for HTML images, and not 'system' images, then it won't matter. Cheers! -- Smug And if it does matter, then you'll have make a copy of the images and place them in the Android 'res/drawable' directory...
 
piggilypoo
Aspiring developer
Profile
Posts: 172
Reg: Jun 28, 2011
San Diego
5,120
like
06/26/13 06:29 PM (11 years ago)
I tried what you mentioned,doing img src="./image.jpg" and the picture stops displaying in the android app. I've added the image to assets, BT_Docs, and res/drawable just for good measure, and it still doesn't display (refreshed, cleaned, and reloaded app). The only way I can seem to get a local image to load from a customHTML screen on android, is to use the file:///android_assets file path.
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
06/26/13 07:08 PM (11 years ago)
I have an app IOS and Android using the same app. My code for Android <img src="myimage.png"></p> With all of the image assets in BT_Doc/myimage.png My code for iOS <img src="myimage.png"></p> With all of the image files in BT_Images/myimage.png * In iOS you can add the images inside of folder but it will not reference that folder because they don't exist as such. so BT_Images/folder1/myimage.png I would still use the same code above <img src="myimage.png"></p> I'm also using the CustomHTML screen with local html files inside my app. Hopefully it helps.
 
piggilypoo
Aspiring developer
Profile
Posts: 172
Reg: Jun 28, 2011
San Diego
5,120
like
06/26/13 08:01 PM (11 years ago)
I don't know why but using that exact code and it still doesn't work for me. Maybe I should also note I'm not using the HTML Doc screen, but the custom HTML screen; im not loading any local HTML screens, but the HTML screen made in the control panel. Using img src="myimage.png" doesn't display any picture.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
06/27/13 12:29 PM (11 years ago)
Hi @piggilypoo. How about an alternative approach. You could upload your image to the BT control panel Files/Media folder and link it to your custom html screen from there. That is guaranteed to work. Alan
 
piggilypoo
Aspiring developer
Profile
Posts: 172
Reg: Jun 28, 2011
San Diego
5,120
like
06/27/13 07:38 PM (11 years ago)
When I do that, I get a weird graphical bug. I have text on the screen as well, which ends up loading before the images can finish loading. When the images finally load, the screen readjusts, but the texts original location on the screen still shows underneath the loaded images, as well as their new location, so the screen looks really messed up.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
06/28/13 01:41 AM (11 years ago)
Something sounds wrong with the html or the image itself. The custom html online editor is OK, but sometimes does something odd to the html code. My suggestion here is to use an offline html editor (e.g. kompozer, or dreamweaver) to produce your html page. Once you have it right on your PC, copy the source into the custom html plugin page.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.