From 8576d3e4c59ae727e319e7859de24deabd7b866f Mon Sep 17 00:00:00 2001 From: Greg Date: Wed, 30 Oct 2019 12:07:24 -0400 Subject: [PATCH] Add BleUtil.java and go:generate commands to create a jar for inclusion by gogio. --- BleUtil.java | 35 +++++++++++++++++++++++++++++++++++ main.go | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 BleUtil.java 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/main.go b/main.go index aa1c48b..d0d623a 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,8 @@ import ( "gioui.org/widget/material" "gioui.org/font/gofont" + + _ "gioui.org/permission/bluetooth" ) type conf struct {