74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
|
//+build android
|
||
|
|
||
|
package main
|
||
|
|
||
|
import "C"
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"os"
|
||
|
|
||
|
ndk "git.wow.st/gmp/android-go/android27"
|
||
|
"gioui.org/ui/app"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
tag *ndk.Char
|
||
|
)
|
||
|
|
||
|
func mkHomeDir() {
|
||
|
msg := ndk.CharWithGoString("getting datadir")
|
||
|
ndk.AndroidLogWrite(ndk.ANDROID_LOG_WARN, tag, msg)
|
||
|
msg.Free()
|
||
|
|
||
|
godir,_ := app.DataDir()
|
||
|
labchan <- fmt.Sprintf("DataDir is %s", godir)
|
||
|
|
||
|
msg = ndk.CharWithGoString("ok. calling mkdir")
|
||
|
ndk.AndroidLogWrite(ndk.ANDROID_LOG_WARN, tag, msg)
|
||
|
msg.Free()
|
||
|
|
||
|
if _, err := os.Stat(godir); !os.IsNotExist(err) {
|
||
|
labchan <- "already exists"
|
||
|
return
|
||
|
}
|
||
|
if err := os.MkdirAll(godir, 0700); err != nil {
|
||
|
fmt.Sprintf("Error creating directory: %s", err)
|
||
|
labchan <- fmt.Sprintf("Error creating directory: %s", err)
|
||
|
} else {
|
||
|
labchan <- "created"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func apiLevel() {
|
||
|
msg := ndk.CharWithGoString("hello log world")
|
||
|
ndk.AndroidLogWrite(ndk.ANDROID_LOG_WARN, tag, msg)
|
||
|
msg.Free()
|
||
|
apilevel := ndk.AndroidGetDeviceApiLevel()
|
||
|
message := fmt.Sprintf("API level is %d", apilevel)
|
||
|
labchan <- message
|
||
|
msg = ndk.CharWithGoString(message)
|
||
|
ndk.AndroidLogWrite(ndk.ANDROID_LOG_WARN, tag, msg)
|
||
|
msg.Free()
|
||
|
}
|
||
|
|
||
|
func getSensors() {
|
||
|
pkg := ndk.CharWithGoString("st.wow.git.jni")
|
||
|
sm := ndk.ASensorManagerGetInstanceForPackage(pkg)
|
||
|
pkg.Free()
|
||
|
sens := ndk.ASensorManagerGetDefaultSensor(sm, ndk.ASENSOR_TYPE_ACCELEROMETER)
|
||
|
stp := ndk.ASensorGetStringType(sens)
|
||
|
labchan <- "sensor" + stp.String()
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
tag = ndk.CharWithGoString("gio")
|
||
|
log.Print("Android starting")
|
||
|
go func() {
|
||
|
apiLevel()
|
||
|
mkHomeDir()
|
||
|
getSensors()
|
||
|
}()
|
||
|
}
|