How to prevent Android default web browser alterin

Community Forums/General Help/How to prevent Android default web browser alterin

Matty(Posted 2015) [#1]
Hi all,

I've looked on google for this and I get lots of results about "changing file assocations" but that's not what I'm after.

I have my own file extension (EP4) for my game which contains the game replay. I have put the appropriate bits and pieces in my app to enable launching a replay directly by clicking on a file in my file browser (my app recognised the extension and opens it in the manner I choose)

That's all good.

The problem is - if I send one of these files by email as a link (to a file hosted externally) then some browsers (on the android device) think they are being helpful by changing the file extension from EP4 to txt (because the extension is not recognised by the browser they are using).

Generally all the sharing of replays takes place within the app itself - which works fine - but one of the options is for users to send a link (for a replay) via sms or email to a friend (who may or may not have the game installed yet) - and this is proving a bit of a problem since when they're browser 'helpfully' alters the file extension - well of course the file can't be launched from their file browser anymore - and even worse - most android devices will let you change the filename but won't let you touch the extension.

(Maybe I'm treating a mobile device a bit too much like an 'open PC' - especially since some of the users devices I've come across don't even have a file browser and those that do won't always allow you to even see files except for a certain narrow range. Heck - it is not even possible to set a default icon for data files in many file browsers since the file browser software itself uses its own set of icons for various files)

Technically this particular feature is a little advanced for the majority of mobile users (not developers) so I can understand why the manufacturers lock down their phones in this manner but it is a little frustrating.


Matty(Posted 2015) [#2]
Edit - just to confirm.....

In most 'file browsers' I can open my data files with my app (much like opening a pdf or similar).

However - it is the various default web browsers on android devices that are changing the extension from .EP4 to .txt when the link is downloaded - when a user downloads a file from a URL in their web browser.....


RemiD(Posted 2015) [#3]

The problem is - if I send one of these files by email as a link (to a file hosted externally) then some browsers (on the android device) think they are being helpful by changing the file extension from EP4 to txt (because the extension is not recognised by the browser they are using).


Really ? That's bad and confusing.


Matty(Posted 2015) [#4]
Yep....it is a known issue - it happens on desktop as well with some versions of IE with files with unrecognised extensions.....

I will be able to find a work around I'm sure - but there are little 'gotchas' that different branded android devices do differently.

For example - my LG phone will let me transfer my .apk file from one phone to another with blue tooth, but if I do so with wi fi direct it refuses.....which is annoying when you have file that is about 30-40MB to transfer (the actual game apk). However my Samsung will let me do either. My friend's Sony phone will allow us to transfer files across but then it refuses to open them - unless we do so via the gmail app (in other words we can't download via a url but we can download through an attachment in an email).....

There are lots of little things here and there related to file transfers that all the manufacturers handle differently (mainly preventing users doing what they want)

Obviously once the app is on an app store like google play it will install and download no problem - but even with 'unknown sources' ticked some devices refuse to play nicely depending on how the app is received, or where it is stored on the device or which app is used to download it......


Matty(Posted 2015) [#5]
Slightly related - at work I develop for android powered smart tvs....particular manufacturers (not ours) do not let you develop native apps even with a developer account but restrict the developer to web technologies (html5, js, css etc) - which I perfectly the understand the reason why but it is a little frustrating....


RemiD(Posted 2015) [#6]
If you want the user to click a link which goes to a webpage (html+css+php) where the file is automatically downloaded as it is (save it in the downloads directory or save it as ...) and not automatically opened in the browser, i have coded something for that.
It allows to download a txt, pdf, jpg, png, mp3, mp4, without opening it, and it works well with windows (internet explorer, firefox, chrome), osx (safari), ubuntu (), android (default browser), ios (documents5 browser)...


Matty(Posted 2015) [#7]
Thanks RemiD - I can open any of those files fine the default browser.

If you want to try an example of what I mean on an android device.... (in this case a samsung s4 - but similar on many others) try downloading any of these files on an android phone in the default browser:

http://mattiesgames.com/convergence/battle_replays/replay_5579f3bd308bb.EP4


This is a sample replay which the browser changes the extension when I download it using that link...

(Feel free to have a look at the file and the folder it is in...it is just a list of replays)


Matty(Posted 2015) [#8]
Edit - you wont be able to do much with the file without the app itself of course.


Matty(Posted 2015) [#9]
Edit: I think I know what I have to do.....to do with mime type....


RemiD(Posted 2015) [#10]
@Matty>>reread my previous post, i have a way to force the download of any file instead of having the browser open it

I can send you a copy of the code (php) to your email address if you want...


Matty(Posted 2015) [#11]
Thanks RemiD - I wouldnt mind having a look at that.


RemiD(Posted 2015) [#12]
Ok i will send an example to the email address of your bb profile.


Matty(Posted 2015) [#13]
All fixed...thanks to RemiD.