First I would like to say that Google should be ashamed. It has taken far too long (24 hours) to get a bluetooth sample app to sort of work and compile using the Android studio for windows. I had to comment out parts of the code until it wouldn't crash. Here is some of what I went through to set up Android Studio and compile the legacy bluetooth chat app.
First I downloaded Android Studio and installed it (with Android-19 and Android-15). I found out that the Gradle plugin that came with it was unsupported by Android studio. So, I had to download Gradle from the gradle site here:
http://www.gradle.org/downloads
I then went to the Bluetooth Chat sample directory in Android-19:
C:\Program Files (x86)\Android\android-studio\sdk\samples\android-19\legacy\BluetoothChat
and imported it...had to select import using external model, selected gradle, had to set the gradle directory to where I installed the new gradle. I also had to uncheck the additional options during import (my memory is a bit fuzzy about this procedure).
Once imported, I tried to compile it and it wouldn't compile..I had to sync the gradle files? That still didn't work. I then closed Android studio and reopened it...viola on the reopen, it started downloading some new libraries? Once this happened I was finally able to get it to compile. I then loaded it onto my Samsung Note 3 phone by connecting the phone through the usb port and letting it install the driver software, and clicking the green play button on the studio.
When it ran, it crashed! So to start debugging what was wrong, I began commenting lines out step by step until I found a
point at which it sort of works…( or at least doesn’t crash right away).
To get my compiled app running on the Note 3 to send data to another phone, I had to download
the same app that someone else had compiled and put onto the google market
place.
I then put this precompiled market app onto my ENVY phone (I am
sending messages between the ENVY and NOTE 3)
When I run the precompiled app on the ENVY and my compiled
app on the NOTE 3, I have to connect to the NOTE 3 from the ENVY (the other way around does not work). Once connected I can send data!!!
UPDATE:
The reason for the app crashing is that it is trying to write information to an actionbar that didn't exist... as described in this blog under "Porting some Android SDK samples"
http://blog.blong.com/search/label/Android
More specifically, I was able to get the app to sort of work by commenting out all the lines that called "setStatus". For example:
setStatus(getString(R.string.title_connected_to, mConnectedDeviceName));
Android was trying to set the status on a status bar that didn't exist, or at least wasn't showing up.
After reading for a few hours, I found the solution for the problem:
I had to change the androidmanifest.xml file because it was trying to use an older version of the API? When Android studio imported the project, the androidmanifest.xml file had a line like this:
" "
for it work correctly (e.g. make the actionbar show up). Once the action bar was available
to the app, I restored the commented out lines and everything works as it should.
Here is the final working androidmanifest.xml listing:
http://blog.blong.com/search/label/Android
More specifically, I was able to get the app to sort of work by commenting out all the lines that called "setStatus". For example:
setStatus(getString(R.string.title_connected_to, mConnectedDeviceName));
Android was trying to set the status on a status bar that didn't exist, or at least wasn't showing up.
After reading for a few hours, I found the solution for the problem:
I had to change the androidmanifest.xml file because it was trying to use an older version of the API? When Android studio imported the project, the androidmanifest.xml file had a line like this:
"
I had to change it to:
to the app, I restored the commented out lines and everything works as it should.
Here is the final working androidmanifest.xml listing:
Thank you man ! I was looking for hours to get this sample running. It works like a charm now (both an Android 4.2 and 2.3 device). Cheers !
ReplyDelete