Creating Android BLE app


if electronics enthusiast, , fond of programming, glad share android ble application development method, can integrate phone , mcu more interesting things. right begin explain how develop android ble application, , can refer official google tutorial. guide packed tutorial, enables build android ble application more , more quickly. of course, i'll upload source code share , can refer official sample sdk/samples/android-18/legacy/bluetoothlegatt.

1. create new android project
open eclipse,file->new->android application project,and fill application name in application name edit box, example, bleexample,or others. minimum required sdk selects api18:android 4.3,and target sdk selects api18:android 4.3,as buletooth 4.0 must android 4.3edition or above. others default unchanged , please continue clicking next button until finish button appears,and click finish button.

2. add permissions , services
add below code in manifest file:
code: [select]
<uses-permission android:name="android.permission.bluetooth"/>
<uses-permission android:name="android.permission.bluetooth_admin"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<service android:name="com.elecfreaks.ble.bluetoothleservice" android:enabled="true"/>


3. create listview item layout file
aiming display each content of listview, here use customization(defining yourself), each listview can show more content,item_list.xml demonstrated below:
code: [select]
<?xml version="1.0" encoding="utf-8"?><linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"   
    >
    <textview android:id="@+id/textviewdevname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textsize="24dp"/>
    <textview android:id="@+id/textviewdevaddress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textsize="12dp"/>
</linearlayout>

copy source code of bleexample /com.elecfreaks.ble project src directory,and open file error prompt, pressing shift+ctrl+o keys.

4. modify activity_main.xml, increasing scanbutton , bledevicelistview
increased contents shown below:
code: [select]
<button
        android:id="@+id/scanbutton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onclick="scanonclick"
        android:text="scan" />

    <listview
        android:id="@+id/bledevicelistview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignleft="@+id/scanbutton"
        android:layout_below="@+id/scanbutton"
        android:layout_above="@+id/sendbutton"
         >
    </listview>


5. in mainactivity.java, add scanbutton mothod of responding events
code: [select]
(onclick="scanonclick")
public void scanonclick(final view v){

}


complete instructions , more details can found @ www.elecfreaks.com/7906.html



Arduino Forum > Community > Exhibition / Gallery > Creating Android BLE app


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code