BBC BASIC
« Accessing an Android public directory »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 6:13pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Accessing an Android public directory  (Read 278 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Accessing an Android public directory
« Thread started on: Jan 14th, 2016, 10:09pm »

Windows provides a number of 'special folders', the paths to which can be discovered by calling the FNspecialfolder() function listed in the BB4W documentation. In a similar way Android provides a number of 'public directories'; I have listed below a function for returning their paths:

Code:
      DEF FN_AndroidPublicDirectory(dir$)
      LOCAL path$, path%, clazz%, env%, fid%, mid%, field%, objcls%, object%, string%
      SYS "SDL_AndroidGetJNIEnv" TO env%
      SYS !(!env%+24),  env%, "android/os/Environment" TO clazz% : REM FindClass
      SYS !(!env%+576), env%, clazz%, dir$, "Ljava/lang/String;" TO fid% : REM GetStaticFieldID
      IF fid% = 0 SYS !(!env%+92),  env%, clazz% : = ""
      SYS !(!env%+580), env%, clazz%, fid% TO field% : REM GetStaticObjectField
      SYS !(!env%+452), env%, clazz%, "getExternalStoragePublicDirectory", \
      \                 "(Ljava/lang/String;)Ljava/io/File;" TO mid% : REM GetStaticMethodID
      SYS !(!env%+456), env%, clazz%, mid%, field% TO object% : REM CallStaticObjectMethod
      SYS !(!env%+124), env%, object% TO objcls% : REM GetObjectClass
      SYS !(!env%+132), env%, objcls%, "getAbsolutePath", \
      \                 "()Ljava/lang/String;" TO mid% : REM GetMethodID
      SYS !(!env%+136), env%, object%, mid% TO string% : REM CallObjectMethod
      SYS !(!env%+676), env%, string%, 0 TO path% : REM GetStringUTFChars
      path$ = $$path%
      SYS !(!env%+680), env%, string%, path% : REM ReleaseStringUTFChars
      SYS !(!env%+92),  env%, objcls% : REM DeleteLocalRef
      SYS !(!env%+92),  env%, object% : REM DeleteLocalRef
      SYS !(!env%+92),  env%, field%  : REM DeleteLocalRef
      SYS !(!env%+92),  env%, clazz%  : REM DeleteLocalRef
      = path$ 

The parameter that is passed to this function may be "DIRECTORY_ALARMS", "DIRECTORY_DCIM", "DIRECTORY_DOCUMENTS", "DIRECTORY_DOWNLOADS", "DIRECTORY_MOVIES", "DIRECTORY_MUSIC", "DIRECTORY_NOTIFICATIONS", "DIRECTORY_PICTURES", "DIRECTORY_PODCASTS" or "DIRECTORY_RINGTONES".

The function also serves as an illustration of how accessing the Android OS tends to be more complicated than the equivalent in Windows. This is largely because the API is Java-based rather than the C/C++ API used by Windows.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls