Giter VIP home page Giter VIP logo

ble-starter-android's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ble-starter-android's Issues

#Android 12 Crashing Issue

This app is crashing on android 12 and ask for Bluetooth permissions which is already mentioned in Manifest file.

connection is not closed if there was a fail while establishing the connection

https://github.com/PunchThrough/ble-starter-android/blob/master/app/src/main/java/com/punchthrough/blestarterappandroid/ble/ConnectionManager.kt

It seems like if a connection fail event happens (for example, the status field is not success and there was a failure while establishing the connection) - the teardownConnection(...) will be called, but without any effect. The teardown function will check for is the device connected/not, and in this particular case the device won't be connected, so essentially "gatt.close()" won't be called.

The app is not working on tablet

Here is the error i am getting in my logcat while running on tablet.

2021-05-11 13:20:22.073 24893-24893/? I/arterappandroi: Late-enabling -Xcheck:jni
2021-05-11 13:20:22.104 24893-24893/? E/arterappandroi: Unknown bits set in runtime_flags: 0x8000
2021-05-11 13:20:22.140 24893-24911/? D/Typeface: Invalid or same font:
2021-05-11 13:20:22.451 24893-24893/com.punchthrough.blestarterappandroid W/arterappandroi: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-05-11 13:20:22.453 24893-24893/com.punchthrough.blestarterappandroid W/arterappandroi: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-05-11 13:20:22.521 24893-24893/com.punchthrough.blestarterappandroid D/ConnectionManager: Added listener com.punchthrough.blestarterappandroid.ble.ConnectionEventListener@b4f48c4, 1 listeners total
2021-05-11 13:20:22.528 24893-24893/com.punchthrough.blestarterappandroid I/SurfaceFactory: [static] sSurfaceFactory = com.mediatek.view.impl.SurfaceFactoryImpl@7368a73
2021-05-11 13:20:22.540 24893-24893/com.punchthrough.blestarterappandroid D/ViewRootImpl[MainActivity]: hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false
2021-05-11 13:20:22.546 24893-24893/com.punchthrough.blestarterappandroid V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@8655acf, this = DecorView@fecec5c[MainActivity]
2021-05-11 13:20:22.602 24893-24893/com.punchthrough.blestarterappandroid E/GraphicExt: Can't load libboost_ext_fwk
2021-05-11 13:20:22.602 24893-24893/com.punchthrough.blestarterappandroid E/GraphicExt: GraphicExtModuleLoader::CreateGraphicExtInstance false
2021-05-11 13:20:22.603 24893-24923/com.punchthrough.blestarterappandroid I/GPUD: @gpudInitialize: successfully initialized with GL, dbg=0 mmdump_dbg=0 mmpath_dbg=0
2021-05-11 13:20:22.624 24893-24923/com.punchthrough.blestarterappandroid D/Surface: Surface::connect(this=0x756453f000,api=1)
2021-05-11 13:20:22.626 24893-24923/com.punchthrough.blestarterappandroid D/Surface: Surface::setBufferCount(this=0x756453f000,bufferCount=3)
2021-05-11 13:20:22.626 24893-24923/com.punchthrough.blestarterappandroid D/Surface: Surface::allocateBuffers(this=0x756453f000)
2021-05-11 13:20:22.636 24893-24923/com.punchthrough.blestarterappandroid W/Gralloc3: mapper 3.x is not supported
2021-05-11 13:20:22.638 24893-24923/com.punchthrough.blestarterappandroid E/ion: ioctl c0044901 failed with code -1: Invalid argument
2021-05-11 13:23:56.909 24893-24893/com.punchthrough.blestarterappandroid D/ScrollableViewRECUtil: user cancel scrollshot
java.lang.Throwable
at android.util.screenscrollshot.ScrollableViewRECUtil.cancel(ScrollableViewRECUtil.java:287)
at android.app.Activity.onScrollScreenshotCancel(Activity.java:972)
at android.app.Activity.onStop(Activity.java:2505)
at androidx.fragment.app.FragmentActivity.onStop(FragmentActivity.java:559)
at androidx.appcompat.app.AppCompatActivity.onStop(AppCompatActivity.java:216)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1473)
at android.app.Activity.performStop(Activity.java:8089)
at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:4648)
at android.app.ActivityThread.handleSleeping(ActivityThread.java:4785)
at android.app.ActivityThread.access$2600(ActivityThread.java:227)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1986)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7405)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
2021-05-11 13:23:56.918 24893-24923/com.punchthrough.blestarterappandroid I/GED: ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 2, oppidx_max 2, oppidx_min 0
2021-05-11 13:24:01.735 24893-24923/com.punchthrough.blestarterappandroid D/Surface: Surface::disconnect(this=0x756453f000,api=1)
2021-05-11 13:24:01.755 24893-24893/com.punchthrough.blestarterappandroid V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@8655acf, this = DecorView@fecec5c[MainActivity]

133 error some time

@cheeyi i facing issue of 133 error code after first time connection but after i put this line of code issue solved
gatt.disconnect() gatt.close()

Connection Priority

How can I change priority?
Tried to use gatt.requestConnectionPriority(1) after services discovered and then stop receiving messages from BLE.

How to FIX Error Status=133 when connecting to BLE devices that are activated from time to time?

Hi, I'm getting error 133 to connect a BLE sensor (Temperature and Humidity). I have executed : device.connectGatt(context, false, callback) and device.connectGatt(context, false, callback,2). 2= BluetoothDevice.TRANSPORT_LE but the problem continues. The connectGatt with 4 parameters using SDK 26. Android version 8.0.0
Any guide/tips or workaround for resolved it?

Thks for your advance

To ensure that the mobile device is compatible with this apk, log trace is attached, with:

  1. Service discovery and get data OK for another device
  2. Error with status = 133, at line 136, for BLE device

Log_ble_starter_2022_0202.txt

Connecting to device results in error 133

Changing one line ConnectionManager.kt:225

device.connectGatt(context, false, callback)

to

device.connectGatt(context, false, callback, BluetoothDevice.TRANSPORT_LE)

solves the problem (although requires to target SDK at least 23)

Connect to several devices

Hi,

I am studying your code and I am interested in getting your opinion on how to connect to several devices at the same time. Your ConnectionManager is Singleton as far as I understand. So how is it possible to be connected to several devices at the same time?

Thanks

C.W.

Disconnection from BLE device on sending commands via Android App version 12.

Hi

I am working on Health & Fitness based android app, which is paired with Smart Ring BLE device. After pairing process app is discovering services for various UUID. For every UUID, app is enabling the Notification, to notify the app whenever any value is triggered from any characteristic. This procedure is working very fine for 95% of android phones.

But I am facing issues with One Plus Nord Android Version 12. Observations are mentioned below :

  • Discover the services -> Enable notification -> Send command to BLE device to receive data from a characteristic -> BLE device disconnecting

  • Discover the services -> Send command to BLE device to receive data from a characteristic -> Enable notification -> Working fine

  • Discover the services -> Send command to BLE device to receive data from a characteristic -> Enable notification -> Worked fine for few minutes but disconnected

-Discover the services -> Send command to BLE device to receive data from a characteristic -> Notification enabled Before -> Worked fine for few minutes but disconnected

-Discover the services -> Send command to BLE device to receive data from a characteristic -> Enable Notification -> No response

I am using same BLE device with other Android model it working very fine no disconnecting issue faced.

I tested this scenario with this github repo and my project facing same behaviour.

What I did to resolve it

  • Network and Bluetooth Reset
  • Bluetooth Cache clear from system app
  • I tried by changing connection interval, slave latency and supervisor timeout in ring side.

Sample code of enabling notification in my project
`
fun queueSetNotificationForCharacteristic(
gatt: BluetoothGatt,
characteristic: BluetoothGattCharacteristic
) {
val ghattQueueItem = GhattQueueItem(
characteristic = characteristic,
enabled = true,
ghatt = gatt,
ghattQueueItemType = SUBSCRIBE_CHARACTERISTIC
)
setNotificationForCharacteristic(ghattQueueItem)
}

private fun setNotificationForCharacteristic(ghattQueueItem: GhattQueueItem) {
ghattQueueItem.ghatt?.let { gatt ->
ghattQueueItem.characteristic?.let { characteristic ->
gatt.setCharacteristicNotification(characteristic, true)
// This is specific to Heart Rate Measurement.
val descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
gatt.writeDescriptor(descriptor, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)
}else{
descriptor.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
gatt.writeDescriptor(descriptor)
}
}
}
}

`
Do I need to get descriptor for other UUIDs too and then write descriptor to enable notification value ??

I am stuck here where and how to proceed furthur.

Application Stop working after receiving notification

Hi ,
I tried the application on my android device , and connect it to my ESP32 via BLE.
I was sending notifications (max 400bytes ) with an MTU of 400, after connecting and updating the MTU I receive about 6 to 9 notifications then the application stop working.

I tested the ESP32 with nRf-app it works fine, other side the same error appear on the app with my two phones ( android 9.0 and android 10)

And Thanks you guys for your efforts.

Build/Run Errors - BLE-Starter-Android App

Hello Chee...I'm very new to programming, but am trying to create an Android app (for my phone running Android 11) that connects to a Bluetooth LE-enabled car battery voltage/current sensor. I've been scouring the Web for example code and came across your "BLE-Starter-Android" app. I cloned and ran the code in Android Studio and the following error (see below) appears to be preventing the app from properly building/running. I'm too novice to understand what it means, but was hoping you would have some insights. Thanks much for your help. - Frank

Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @11087f2f

Can't find proprietary service

Hi,
While using BLE Starter project, i can't find my proprietary characteristic in list of discovered characteristics.

My proprietary service is : "0000ffe0-0000-1000-8000-00805f9b34fb"
and associated characteristic is: "0000ffe1-0000-1000-8000-00805f9b34fb"

I followed the Android Ble Guide on Punch Through website and encountered problem while reading this characteristic. This is the main reason why i wanted to test with BLE Starter, and check the difference with my code.

The problem i encounter with my piece of code is a disconnection of my ble device as soon as my android app sends a command (well received by the device)

Maybe there is something i don't understand about services/characteristics that is the reason why it is not discovered in BLE Starter...

This could really help me with my own code.

Thanks

ConnectionManager.teardownConnection(device) is making my app crash.

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.halosleep.bassinest, PID: 20612
java.lang.IllegalArgumentException: Navigation action/destination com.halosleep.bassinest:id/action_connectionLoadingFragment_to_errorFragment cannot be found from the current destination Destination(com.halosleep.bassinest:id/bleScanFragment) label=fragment_ble_scan class=com.halosleep.bassinest.ui.activity.wifi.wifiFragments.BleScanFragment
at androidx.navigation.NavController.navigate(NavController.kt:1540)
at androidx.navigation.NavController.navigate(NavController.kt:1472)
at androidx.navigation.NavController.navigate(NavController.kt:1930)
at com.halosleep.bassinest.ui.activity.wifi.wifiFragments.BleScanFragment$moveToErrorPage$1.invokeSuspend(BleScanFragment.kt:464)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7884)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@47f45d4, Dispatchers.Main]

Convert to java

I'm currently working on a project trying to merge part of your code into mine. However I'm using java for the most part and running into many errors when using the build in tools to convert Kotlin to Java. Are you planning on developing this tool in java as well? Could help with that!

Write and Read

If i want to read and write a string than how can i do it like nrfConnect ?

Support for Android 12?

Hi I just upgraded my phone to Android 12 and my application stopped working due to the runtime permission and enable ble intent etc. I just wanted to know if you guys are working on migrating the permissions to the new standard with Android 12?.
If not is there any possibility that i can get some guidance into this matter?

Kind regards
Zaher

Exchange Activity in Fragment

Hi,

thanks for the great example here just one question. I've tranferred all the example code into one fragment which incorporates a bottom navigation bar. So far scanning and the recycler works as expected. But when I click on a device in the list I expect to exchange the activity with:

    private val connectionEventListener by lazy {
        ConnectionEventListener().apply {
            onConnectionSetupComplete = { gatt ->

                Intent(activity!!, BleOperationsActivity::class.java).also {
                    it.putExtra(BluetoothDevice.EXTRA_DEVICE, gatt.device)
                    requireActivity().startActivity(it)
                }
                ConnectionManager.unregisterListener(this)
            }
            onDisconnect = {
                activity?.runOnUiThread {
                    alert {
                        title = "Disconnected"
                        message = "Disconnected or unable to connect to device."
                        positiveButton("OK") {}
                    }.show()
                }
            }
        }
    }

But this does not work. It does not throw errors and I can see that the ble device gets connected but the activity is not changed and therefore I cannot see the BleOperationsActivity.
Do you have any suggestion?

Kind regards,

C.W.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.