Page 1 of 1

Androd: File Requester

Posted: Wed Apr 22, 2020 1:16 pm
by ljgww
I have a piece of code which triggers opening a local file via file requester.

Code: Select all

OpenFileRequester("", @CallbackOpenLocalFileRequester())
When I am in the browser i can put something like ".txt" as first parameter and browser pop with file selector and will show only .txt files. When I try to do this on Android I do not get file selector at all.

If I make it as above (leave it empty), file selector appears. It looks like as if on android there are other rules for this first parameter.

Are there some guidelines for non registered mime types?

I am aware of the fact that normally in this parameter also takes mime type, for example "text/plain" but I would like to use a file extension that is not registered as standard mime type (and I did not find a way to influence/customize mime type that spider basic can recognize). Hints welcome.

Tried with standard Mime types and they seem to work on android just open different file selector.

Note that file selector, at first, did not work at all, until I realized that application needs a 'storage' permission in order to access local files.

Another question here is: Is it possible to trigger app asking for permissions?

Re: Androd: File Requester

Posted: Fri Apr 24, 2020 3:13 pm
by ljgww
Related to above...

Documentation quote:
#PB_Compiler_OS : Determines on which OS the compiler is currently running. It can be one of the following values:
#PB_OS_Windows : The compiler is creating Windows executable (PureBasic)
#PB_OS_Linux : The compiler is creating Linux executable (PureBasic)
#PB_OS_AmigaOS : The compiler is creating AmigaOS executable (PureBasic)
#PB_OS_MacOS : The compiler is creating OS X executable (PureBasic)
#PB_OS_Web : The compiler is generating a JavaScript file (SpiderBasic)
Now both browser and android app would be (i guess) #PB_OS_Web.

Is it possible to determine at compile time (even at runtime would be fine) if code is for browser or for android?

So that it is either - appropriate code is generated (platform specific) OR there would be code that can conditionally run depending on platform at the run time?

Re: Androd: File Requester

Posted: Mon May 25, 2020 2:53 am
by RobertRioja
Here is how I solved the problem:

Code: Select all


#Android = #True         ; or #False

;- Open the main window.
CompilerIf #PB_Compiler_OS = #PB_OS_Web
  CompilerIf #Android = #False
    WindowMain = OpenWindow(#PB_Any, 0, 0, 900, 600, "", #PB_Window_Background)
    BindEvent(#PB_Event_SizeWindow, @Event_Resize())

  CompilerElse
    WindowMain = OpenWindow(#PB_Any, 0, 0, 800, 600, "", #PB_Window_SystemMenu) ; | #PB_Window_ScreenCentered)

  CompilerEndIf

CompilerElse
  Global ProgramPath$ = GetPathPart(ProgramFilename())
  WindowMain = OpenWindow(#PB_Any, 0, 0, 900, 600, ProgName$, #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_Maximize)
  BindEvent(#PB_Event_SizeWindow, @Event_Resize())

CompilerEndIf
I created a constant I call #Android. Then I set it to either #True or #False according to my needs. Notice that I only need to test for it when I know that the OS is Web. The last CompilerElse allows me to compile with PureBasic for Windows apps.

I realize that this is not as automatic as #PB_Compiler_OS, but it was the best I could come up with.

Hope this helps.

Re: Androd: File Requester

Posted: Mon May 25, 2020 3:49 am
by plouf
dont know about filytype requestest but about platform

Debug "Platform: " + DeviceInfo(#PB_Device_Platform)

can tell you if its android or not

Re: Androd: File Requester

Posted: Mon Jun 22, 2020 1:10 pm
by ljgww
@RobertRioja

thank you for the effort. One can force different compilation when building this or that version.
My point is that it would be nice to have constant that tells us which platform we are on so it is easy to opt different code accordingly.

Re: Androd: File Requester

Posted: Mon Jun 22, 2020 1:15 pm
by ljgww
plouf wrote:dont know about filytype requestest but about platform

Debug "Platform: " + DeviceInfo(#PB_Device_Platform)

can tell you if its android or not
Thank you. Shall try it.