From 0ab45a1d9d5492ee4239c7aec656cb2feae3577b Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 1 Nov 2019 14:48:17 -0400 Subject: [PATCH] Update Gio verion (change location of permissions). Put the java file here and add go:generate commands to create the jar file. --- .gitignore | 1 + BleUtil.java | 35 +++++++++++++++++++++++++++++++++++ ble_android.go | 7 ++++++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 BleUtil.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d392f0e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.jar diff --git a/BleUtil.java b/BleUtil.java new file mode 100644 index 0000000..8b582d3 --- /dev/null +++ b/BleUtil.java @@ -0,0 +1,35 @@ +package st.wow.git.ble; + +import java.lang.Runnable; +import android.util.Log; +import java.lang.Class; +import java.lang.ClassLoader; +import java.lang.reflect.Constructor; +import android.os.Handler; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothManager; +import android.content.Context; +import android.content.Intent; + +public class BleUtil { + public void Enable(Context ctx) { + Log.d("gio", "BleUtil Enable: manager"); + BluetoothManager manager = (BluetoothManager) ctx.getSystemService(ctx.BLUETOOTH_SERVICE); + Log.d("gio", "BleUtil Enable: adapter"); + BluetoothAdapter ad = (BluetoothAdapter) manager.getAdapter(); + if (ad == null || !ad.isEnabled()) { + Log.d("gio", "BleUtil Enable: handler"); + Handler handler = new Handler(ctx.getMainLooper()); + //BleEnabler en = new BleEnabler(ctx, ad); + Log.d("gio", "BleUtil Enable: Intent"); + Intent enableBtIntent = new Intent(ad.ACTION_REQUEST_ENABLE); + Log.d("gio", "BleUtil Enable: handler.post"); + handler.post(new Runnable() { + public void run() { + ctx.startActivity(enableBtIntent); + } + }); + } + } +} + diff --git a/ble_android.go b/ble_android.go index 1764404..41f046e 100644 --- a/ble_android.go +++ b/ble_android.go @@ -1,9 +1,14 @@ +//go:generate mkdir -p classes +//go:generate javac -bootclasspath $ANDROID_HOME/platforms/android-29/android.jar -d classes BleUtil.java +//go:generate jar cf BleUtil.jar -C classes . +//go:generate rm -rf classes + package ble import ( "log" "gioui.org/app" - _ "gioui.org/permission/bluetooth" + _ "gioui.org/app/permission/bluetooth_le" ) /*