- The only difference between coding for html/windows/linux/bsd/osx and Android or IOS is the availability of the GPS and Accelorometer libraries.
- Android uses .apk files and IOS uses .ipa
- SB uses Java JDK for Android. You get it from here. The latest version at time of posting is "8U121". 64bit has a slight performance advantage at compile time, but they all make the same .apk
- SB uses frameworks like Apache Cordova, Apache ANT, Node.JS and others for all the cross-platform magic in the background. No documentation or examples on plugin dev at time of writing
- Install SDK
- In SB IDE go to File>Preferences>Compiler and set JDK path. Mine was "C:\Program Files\Java\jdk1.8.0_112\" and click "Apply" then "Ok"
- In SB paste this demo code in to the IDE(or your own code)
Code: Select all
Declare drawspecs() Declare resize() Declare.l RDesktopHeight() Declare.l RDesktopWidth() Global width.l Global height.l Global accell.l Global geol.l accell=StartAccelerometer(3000) geol=StartGeolocation() If OpenWindow(0,0,0,RDesktopWidth(),RDesktopHeight(),"",#PB_Window_Background) CanvasGadget(0,0,0,WindowWidth(0),WindowHeight(0),#PB_Canvas_Keyboard) AddWindowTimer(0,33,2000) BindEvent(#PB_Event_SizeDesktop,@resize()) drawspecs() EndIf Procedure resize() width=RDesktopWidth() height=RDesktopHeight() ResizeGadget(0,0,0,width,height) drawspecs() EndProcedure ;draw HTTP GET results Procedure httpevent(Success, Result$, UserData) Protected draw.l draw=StartDrawing(CanvasOutput(0)) DrawingMode(#PB_2DDrawing_Transparent) If Success DrawText(1,65,"Network: Connected",RGB(255,255,255)) Else DrawText(1,65,"Network: Disconnected",RGB(255,255,255)) EndIf If draw : StopDrawing() : EndIf EndProcedure ;draw some data Procedure drawspecs() Protected aspect$ ;get aspect/rotation If RDesktopWidth()>RDesktopHeight() aspect$="Landscape" Else aspect$="Verticle" EndIf StartDrawing(CanvasOutput(0)) DrawingMode(#PB_2DDrawing_Transparent) Box(0,0,WindowWidth(0),WindowHeight(0),RGB(0,0,0)) ;draw resolution DrawText(1,1,"Resolution: "+Str(RDesktopWidth())+"x"+Str(RDesktopHeight()),RGB(255,255,255)) ;draw aspect/rotation DrawText(1,33,"Aspect: "+aspect$,RGB(255,255,255)) ;draw accelerometer sensor data If accell<>0 DrawText(1,97,"Accelorometer X: "+AccelerometerX(),RGB(255,255,255)) DrawText(1,129,"Accelorometer Y: "+AccelerometerY(),RGB(255,255,255)) DrawText(1,161,"Accelorometer Z: "+AccelerometerZ(),RGB(255,255,255)) DrawText(1,193,"Accelorometer Time: "+AccelerometerTime(),RGB(255,255,255)) Else DrawText(1,97,"Accelorometer: N/A",RGB(255,255,255)) EndIf ;draw gps chip data If geol<>0 DrawText(1,225,"GPS Long: "+GeolocationLongitude(),RGB(255,255,255)) DrawText(1,257,"GPS Lat: "+GeolocationLatitude(),RGB(255,255,255)) DrawText(1,289,"GPS Alt: "+GeolocationAltitude(),RGB(255,255,255)) DrawText(1,321,"GPS Deg: "+GeolocationHeading(),RGB(255,255,255)) DrawText(1,353,"GPS Speed: "+GeolocationSpeed(),RGB(255,255,255)) Else DrawText(1,225,"GPS: N/A",RGB(255,255,255)) EndIf StopDrawing() HTTPRequest(#PB_HTTP_Get,"https://www.google.com","",@httpevent()) EndProcedure ;real width Procedure.l RDesktopWidth() Protected pixels.f EnableJS v_pixels=window.devicePixelRatio.toPrecision(21); DisableJS ExamineDesktops() ProcedureReturn Val(StrF(pixels * ValF(Str(DesktopWidth(0))))) EndProcedure ;real height Procedure.l RDesktopHeight() Protected pixels.f EnableJS v_pixels=window.devicePixelRatio.toPrecision(21); DisableJS ExamineDesktops() ProcedureReturn Val(StrF(pixels * ValF(Str(DesktopHeight(0))))) EndProcedure
- On your Android test device go to Settings and if you don't see "Developer Options" go to "About Phone" and tap "Build number" 7-times to enable it
- Under Settings>Developer Options on your device enable "USB debugging" and "Verify apps over USB"
- On your PC in SB IDE in the Android tab you still have open fill in "App Name"(any string), "Version"(any float), "Icon"(any PNG), "Package ID"(anything *.*.* format). Uncheck "Fullscreen" and "Geolocation"(the first hijacks the screen and the second doesn't actually do anything). Make sure orentation is "Anything". Fill in "Output Filename"(I just put "testy.apk"). And check "Automatically upload on USB devices". Click "OK"
- Save your SB file somewhere, preferably it's own folder using File>Save As
- Click Compiler>Create App and go to the Android tab
- Click "Create App" and wait for the status window to go away
- Go on to your device and your app will be on the last page of your app pages ready to be run(It also auto-runs SB B2.10+). You also have the .apk in the same directory as your .sb file ready to be signed and distributed.
#6+ are all that's required in the future. You can disable debug and develop-options and enable Security>Unknown source and bring in your .apk over Bluetooth or USB file transfer or any other means. You should disable Security>Unknown source typically though, because it's one-half of Android's security.