Kotlin 101: How to communicate to a Bluetooth device Part 1

  Переглядів 74,918

Apptaura

Apptaura

6 років тому

In this tutorial I will be taking you through writing an android app in Kotlin that can connect to and communicate with a Bluetooth device.
This will include working with the Android BluetoothSocket to send data and the Android BluetoothAdapter class to find and connect with paired devices. We will also be looking at Async tasks to connect to the device.
...................................................................................
Website: www.appsinthesky.com
Twitter: / appsinthesky
GitHub: github.com/appsinthesky/Kotli...
Arduino Code: bit.ly/ExampleArduinoCode

КОМЕНТАРІ: 53
@armansattar6710
@armansattar6710 3 роки тому
Thank you so much for this. There aren't many useful guides on how to start using Bluetooth and yours was concise and brilliant.
@guynimni382
@guynimni382 5 років тому
Great tutorial! Tnx for taking the time to record it. I just wanted to have a quick start with communicating with the Arduino via Bluetooth. Next step for me is to dig deep into the Kotlin+Android fundamentals in order to better understand some of the things you did in the video :)
@K0nzerv
@K0nzerv 4 роки тому
Thank you for this tutorial, you saved me tonnes of time.
@carlosproduction4183
@carlosproduction4183 4 роки тому
Just a question, I have to do something about "position" in (your) line 58, do I have to initialize it in some way (val position:Int = 1 ?) Thank you anyway !
@user-pq1gt7kv5g
@user-pq1gt7kv5g 4 роки тому
Thanks for your tutorial
@mannhansen9337
@mannhansen9337 4 роки тому
Thanks for sharing this tutorial. How can I import it into Android Studio version 3.5.3 ? I have tried but get lots of errors. Looks like compatibility issues with the new version ?
@aqualk3722
@aqualk3722 4 роки тому
Thanks it helped.can you update the code for see the name of bt device on listview and reading data
@mattgewain7743
@mattgewain7743 4 роки тому
Very Good tutorial. But the font on Android Studio is to small for me to read except on my biggest monitor. I wish I could see it better.
@zainablawal97
@zainablawal97 Рік тому
Hi Apptaura, Thank you so much for this tutorial. Is there a way i can receive data from an arduino hc-06 Bluetooth device?
@scodedead9061
@scodedead9061 4 роки тому
Great tutorial !!! but i always get could'nt connect ( HC-5 ) to arduino , huft i did not see any error ,should i ???
@loriklassen2416
@loriklassen2416 5 років тому
The arduino code listed doesnt correspond with the what the tutorial teaches. Where can i find the correct android sketch
@jaumebobet9998
@jaumebobet9998 5 років тому
Is there a way to show in the ListView te connected device names instead or together with de device MAC address ?. Thank you in advance. Apart from this issue, your example and explanations are great. I've learned a lot and I customized it for my own purpouses. It works very well
@guynimni382
@guynimni382 5 років тому
Don't know if it's relevant after so much time passed :) What I did was to add a new array that holds only the device names and pass it to the listView. private fun pairedDeviceList() { m_pairedDevices = m_bluetoothAdapter!!.bondedDevices val list : ArrayList = ArrayList() val listOfNames : ArrayList = ArrayList() // Added if (!m_pairedDevices.isEmpty()) { for (device: BluetoothDevice in m_pairedDevices) { list.add(device) listOfNames.add(device.name); // Added Log.i("device", ""+device.name) } } else { toast("no paired bluetooth devices found") } val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, listOfNames) // Changed to listOfNames select_device_list.adapter = adapter select_device_list.onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ -> val device: BluetoothDevice = list[position] val address: String = device.address val intent = Intent(this, ControlActivity::class.java) intent.putExtra(EXTRA_ADDRESS, address) startActivity(intent) } }
@frootyfloyd9398
@frootyfloyd9398 3 роки тому
@@guynimni382 Great!
@danny117hd
@danny117hd 2 роки тому
Presentation size coding window please. Or maybe use the magnifier
@samqueen8337
@samqueen8337 2 роки тому
If your list does appear it may be because the font and the text color are both set to white. Try changing the background-color of your list
@geekmustafa
@geekmustafa 5 років тому
Thinks bro but if u can make one about received data plz 😊
@jamesedwards9054
@jamesedwards9054 4 роки тому
The items are not showing in my list view...
@MyVoid312
@MyVoid312 3 роки тому
any idea on how to do it on java?
@freedomphiliplachica5414
@freedomphiliplachica5414 3 роки тому
I'm getting error. The word list is underlined red saying: expression 'list' of type 'kotlin.collections.ArrayList /* = java.util.ArrayList */' cannot be invoked as a function what should I do?
@emethp7751
@emethp7751 6 років тому
Is this tutorial applicable in communication between a Bluetooth low energy beacon and a phone that supports the same?
@apptaura8131
@apptaura8131 6 років тому
Hi Emeth, thanks for the comment. Unfortunately Bluetooth and Bluetooth low energy are two completely different technologies. However we may look into doing a tutorial on Bluetooth low energy at a later date.
@riekje321
@riekje321 5 років тому
Would be nice. Thanks.
@robertauer2763
@robertauer2763 4 роки тому
Something has changed - I'm following the instructions to the letter and I keep getting: "AndroidManifest.xml:13:9-17:25: AAPT: error: unexpected element found in " and the android:name is in Red.
@ilkesert1050
@ilkesert1050 3 роки тому
Unresolved reference: select_device_refresh. I have this problem on MainActivity but i haven't got any problem at activty_mainly CAN U HELP
@omeryumusak6900
@omeryumusak6900 3 роки тому
add build.gradle this code plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-android-extensions' }
@omeryumusak6900
@omeryumusak6900 3 роки тому
türkmüşsün zaten bu kodları ekle
@krisjanisnoviks120
@krisjanisnoviks120 2 роки тому
@@omeryumusak6900 thank you :)
@cassidygonzalez374
@cassidygonzalez374 Рік тому
Add this line above the line that uses select_device_refresh: val select_device_refresh = findViewById(R.id.select_device_refresh) as Button
@hugopetrucci3938
@hugopetrucci3938 2 роки тому
there are many things that don´t work on android studio 4.2.2 , please describe version that you use
@hugopetrucci3938
@hugopetrucci3938 2 роки тому
3.0.1
@jayverma1870
@jayverma1870 2 роки тому
kindly zoom your code when you record video
@smyra
@smyra 3 роки тому
Hi, I don't know if you still follow this but I'll give a try for my question. First, I want to thank you for this tutorial. I'm unfortunately late and pretty new on this. Now, I'm using AndroidStudio do lots of things have been changed, I assume. I used all your coding, butI'm getting some error and unfortunately again I couldn't solve it and also find on the net. So maybe you can help me with this. Android gives an error at the SelectDeviceActivity class with this code: "val intent= Intent(this, academy.mestim.neurostimulator.ControlActivity: :class.java)" with the error: " e: C:\Users\smyra\AndroidStudioProjects euroStimulator\app\src\main\java\academy\mestim eurostimulator\SelectDeviceActivity.kt: (63, 84): Expecting ')' ". I tried "alt + enter" but it didn't help either. So, waiting for your help. Have a nice day
@alanlowe9716
@alanlowe9716 3 місяці тому
Ditto. It is difficult to follow this tutorial when everything he types is deprecated.
@V3NG3ANC33
@V3NG3ANC33 6 років тому
Link to that wallpaper pls?!
@apptaura8131
@apptaura8131 6 років тому
Hi zyyystan, thanks for the comment. Here is a link to the wallpaper: bit.ly/2GB4dbu
@DrequimaX
@DrequimaX 4 роки тому
Sir, can u tell how to display message from BT device, I used m_bluetoothSocket!!.inputStream.read(output.toByteArray()), but it is not working!
@ryszardal2631
@ryszardal2631 3 роки тому
hi, did u solved it?
@Jim1Dean
@Jim1Dean 3 роки тому
@@ryszardal2631 i want to know it too
@videos4mydad
@videos4mydad Рік тому
Unfortunately a lot of code in this tutorial is now "deprecated" and we cannot simply follow the tutorial step by step. I am trying to find a more recent tutorial.
@pascalschaer
@pascalschaer Рік тому
same. Have you found anything?
@videos4mydad
@videos4mydad Рік тому
@@pascalschaer I am learning Flutter and Dart. That way I can write it once and use it on Android and iOS. Unfortunately, using bluetooth on something like React Native and Expo frameworks is a complete pain in the ass even though I am familiar with React.
@zenon5940
@zenon5940 4 роки тому
Your tutorial is quite interesting BUT .... it would be so much more interesting if we could read more easily what you show us on your monitor, Have you ever considered having more contrast like for instance black otext on white background ?
@scottcarrington1023
@scottcarrington1023 4 роки тому
Could it be your internet connection? I was having troubles in some areas, too, but after restarting my modem and going full screen on the video, the text was crystal clear.
@tryJOCIM
@tryJOCIM Рік тому
0dp didnt work
@MyVoid312
@MyVoid312 3 роки тому
Damn if it was in java ://
@CharlesGouin
@CharlesGouin 5 років тому
You could have made this video much sorter by showing less of the design process. Your title is "How to communicate to a Bluetooth device", not "Android studio 101". Great video anyway and thx!
@apptaura8131
@apptaura8131 5 років тому
Hi Ozkee, thanks for the comment. We will keep this in mind for future turorials.
Kotlin 101: How to communicate to a Bluetooth device Part 2
31:07
Анита просто на химии, поэтому такая сильная
00:21
Женя Лизогуб SHORTS
Переглядів 2,8 млн
I PUT MY ARMOR ON (Creeper) (PG Version)
00:19
Sam Green
Переглядів 6 млн
Building Android Apps to Control Bluetooth LE Devices
38:51
CrossComm, Inc.
Переглядів 34 тис.
Kotlin 101: How to communicate via Serial Connection Part 1
8:55
How to Use Device Sensors the Right Way in Android - Android Studio Tutorial
25:08
Bluetooth Arduino RECEIVE data + Chart
9:26
Electronoobs
Переглядів 301 тис.
Foreground Services - Android Basics 2023
22:22
Philipp Lackner
Переглядів 59 тис.
Bluetooth Tutorial - Sending/Receiving Data with Bluetooth (Part 1/4)
8:00
CodingWithMitch
Переглядів 200 тис.
.NET Framework vs .NET Core vs .NET vs .NET Standard vs C#
25:14
IAmTimCorey
Переглядів 528 тис.
Everything you need to know about Bluetooth Low Energy advertising
1:03:22
Nordic Semiconductor
Переглядів 30 тис.
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Переглядів 21 тис.
Анита просто на химии, поэтому такая сильная
00:21
Женя Лизогуб SHORTS
Переглядів 2,8 млн