一、例程简介

1、应用界面图(主界面、设置界面)

 

2、实现功能:

(1)打开应用,显示主界面,检测蓝牙功能是否打开,否则询问打开;

(2)打开蓝牙功能后,点击“连接设备:”下的按钮选择已匹配的蓝牙设备进行连接;

(3)若蓝牙设备未匹配,可点击旁边的 […] 按钮打开系统蓝牙设置界面,进行蓝牙匹配;

(4)点击中央的上、下、左、右和中间按钮,可发送不同的蓝牙字符串消息;

(5)蓝牙消息内容可通过点击 [设置] 按钮在设置界面中设置,设置的数据重启应用后依然有效;

(6)其中,中间按钮具有长按按下、长按释放和点击三种不同效果;

(7)本应用还附带来电监听功能,有来电时,会自动发送蓝牙消息;

(8)点击 [退出] 按钮,关闭蓝牙连接,并且关闭安卓设备蓝牙功能。

二、工程目录

三、主界面代码

MainActivity.java

package com.example.z.buletoothdemo;import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import java.util.UUID;public class MainActivity extends AppCompatActivity {public final static String TAG = "MainActivity";private Button bdevice;private EditText emessage;private Button btmid;private BluetoothAdapter ba;private ArrayList<String> lname = new ArrayList<>();private ArrayList<String> laddress = new ArrayList<>();private String sdname;private String sdaddress;private BluetoothSocket bsocket = null;private OutputStream ostream = null;private InputStream istream = null;private static final UUID SerialPort_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");private Handler hd;private ReceiveThread rt;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);bdevice = (Button) findViewById(R.id.btn_dev_name);emessage = (EditText) findViewById(R.id.et_message);btmid = (Button)findViewById(R.id.btn_mid);btmid.setOnTouchListener(new MidOnTouchListener());ba = BluetoothAdapter.getDefaultAdapter();hd = new Handler() {public void handleMessage(Message msg){super.handleMessage(msg);if(msg.what == 111) {SharedPreferences preferences = getSharedPreferences("messages", MODE_PRIVATE);String ms = preferences.getString("msg_mlg", "5");SendStr(ms);}else if(msg.what == 112) {emessage.setText(Arrays.toString((byte[])msg.obj));emessage.setEnabled(true);}}};// When "Device does not support Bluetooth"if (ba == null) {Toast.makeText(getApplicationContext(),getResources().getString(R.string.dev_nsup_bt),Toast.LENGTH_SHORT).show();}// When Bluetooth hasn't opened, enable itif (!ba.isEnabled()) {Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);startActivityForResult(turnOn, 0);}}// Function to send Bluetooth messagepublic void SendStr(String str) {byte[] bf = new byte[33];bf = str.getBytes();if((!str.equals("")) && (bsocket!=null)) {try {ostream = bsocket.getOutputStream();ostream.write(bf);ostream.write('\0');    // Send an ending sign} catch (IOException e) {e.printStackTrace();}try {if (ostream != null) {ostream.flush();}} catch (IOException e) {e.printStackTrace();}emessage.setText("");}}// Thread to receive Bluetooth messagepublic class ReceiveThread extends Thread {BluetoothSocket tsocket;public ReceiveThread(BluetoothSocket socket) {this.tsocket = socket;InputStream tistream = null;try {tistream = socket.getInputStream();} catch (IOException e) {e.printStackTrace();}istream = tistream;}@Overridepublic void run() {byte[] buffer = new byte[32];String str;// Keep on receivingwhile (true) {try {istream.read(buffer);str = new String(buffer,"UTF-8");buffer = new byte[32];Message msg = hd.obtainMessage(112,str);hd.sendMessage(msg);} catch (IOException e) {try {if (istream != null) {istream.close();}break;} catch (IOException e1) {e1.printStackTrace();}}try {Thread.sleep(50);} catch (InterruptedException e) {e.printStackTrace();}}}}// Listener to catch the RINGING STATEclass MyPhoneStateListener extends PhoneStateListener {@Overridepublic void onCallStateChanged(int state, String incomingNumber) {Log.i(TAG, "in coming number:" + incomingNumber);if(state == TelephonyManager.CALL_STATE_RINGING) {SharedPreferences preferences = getSharedPreferences("messages", MODE_PRIVATE);String ms = preferences.getString("msg_ring", "0");SendStr(ms);}super.onCallStateChanged(state, incomingNumber);}}// Function of the ChooseDev Buttonpublic void ChooseDevOnClick(View Source) {Set<BluetoothDevice> sdevices;// Clear data of scanninglname.clear();laddress.clear();// Get data of boned devicessdevices = ba.getBondedDevices();if (sdevices.size() > 0) {for (BluetoothDevice btd : sdevices) {lname.add(btd.getName());laddress.add(btd.getAddress());System.out.println(btd.getName() + btd.getAddress());}}// Prepare data for the list of Bluetooth devicesint size = lname.size();final String[] snames = new String[size];final String[] saddresses = new String[size];for (int i = 0; i < size; i++) {snames[i] = lname.get(i);saddresses[i] = laddress.get(i);}// Buld AlertDialog of the list of Bluetooth devicesAlertDialog.Builder ab = new AlertDialog.Builder(MainActivity.this);ab.setTitle(getResources().getString(R.string.choose_bt_dev));ab.setItems(snames, new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {// The name and address of the chosen devicesdname = snames[which];sdaddress = saddresses[which];// Connect to chosen deviceBluetoothDevice device = ba.getRemoteDevice(sdaddress);try {bsocket = device.createRfcommSocketToServiceRecord(SerialPort_UUID);ba.cancelDiscovery();bsocket.connect();// Set a phone state listenerTelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);tm.listen(new MyPhoneStateListener(),PhoneStateListener.LISTEN_CALL_STATE);// Start a thread to receive bluetooth messagert = new ReceiveThread(bsocket);rt.start();} catch (IOException e) {// Set fail messagesdname = getResources().getString(R.string.con_fail);try {bsocket.close();bsocket = null;} catch (IOException e2) {e2.printStackTrace();}e.printStackTrace();}// Show result of connectionbdevice.setText(sdname);}});// Pop the list AlertDialogab.create().show();}// Function of the Exit Buttonpublic void ExitOnClick(View Source) {if(bsocket != null)try {bsocket.close();}catch (IOException e) {e.printStackTrace();}// Close Bluetoothba.disable();MainActivity.this.finish();}// OnTouchListener for Mid Buttonclass MidOnTouchListener implements View.OnTouchListener {private int long_pressed = 0;@Overridepublic boolean onTouch(View v, MotionEvent event) {if(event.getAction() == MotionEvent.ACTION_DOWN){// Thread to test long pressedThread t = new Thread() {@Overridepublic void run() {super.run();try {Thread.sleep(250);}catch (InterruptedException e){e.printStackTrace();}// test flagif(long_pressed == 0) {long_pressed = 1;   // Set flaghd.sendEmptyMessage(111);   // Do long-pressed-action}else {long_pressed = 0;}}};t.start();}if(event.getAction() == MotionEvent.ACTION_UP){if(long_pressed == 0) { // Flag not set, do click-actionlong_pressed = -1;SharedPreferences preferences = getSharedPreferences("messages", MODE_PRIVATE);String ms = preferences.getString("msg_msh", "0");SendStr(ms);}else if(long_pressed == 1) {   // Long pressed endSharedPreferences preferences = getSharedPreferences("messages", MODE_PRIVATE);String ms = preferences.getString("msg_mup", "6");SendStr(ms);long_pressed = 0;}}return false;}}// Function of Up Buttonpublic void UpOnClick(View Source) {SharedPreferences preferences = getSharedPreferences("messages", MODE_PRIVATE);String ms = preferences.getString("msg_up", "1");SendStr(ms);}// Function of Down Buttonpublic void DownOnClick(View Source) {SharedPreferences preferences = getSharedPreferences("messages", MODE_PRIVATE);String ms = preferences.getString("msg_down", "3");SendStr(ms);}// Function of Left Buttonpublic void LeftOnClick(View Source) {SharedPreferences preferences = getSharedPreferences("messages", MODE_PRIVATE);String ms = preferences.getString("msg_left", "4");SendStr(ms);}// Function of Right Buttonpublic void RightOnClick(View Source) {SharedPreferences preferences = getSharedPreferences("messages", MODE_PRIVATE);String ms = preferences.getString("msg_right", "2");SendStr(ms);}// Function of Send Buttonpublic void BtnSendOnClick(View Source) {String str = emessage.getText().toString();SendStr(str);}// When "…" Button clicked, open system activity to Bluetooth settingspublic void SearchOnClick(View Source) {startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS));}// When Settings Button clicked, open SettingsActivitypublic void SettingsOnClick(View Source) {Intent intent = new Intent(this, SettingsActivity.class);startActivity(intent);}}

四、设置界面代码

SettingsActivity.java

package com.example.z.buletoothdemo;import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;/*** Created by Z on 2016/5/26.*/
public class SettingsActivity extends AppCompatActivity {private EditText etup;private EditText etdown;private EditText etleft;private EditText etright;private EditText etmsh;private EditText etmlg;private EditText etmup;private EditText etring;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_settings);etup = (EditText)findViewById(R.id.et_up);etdown = (EditText)findViewById(R.id.et_down);etleft = (EditText)findViewById(R.id.et_left);etright = (EditText)findViewById(R.id.et_right);etmsh = (EditText)findViewById(R.id.et_msh);etmlg = (EditText)findViewById(R.id.et_mlg);etmup = (EditText)findViewById(R.id.et_mup);etring = (EditText)findViewById(R.id.et_ring);SharedPreferences preferences = getSharedPreferences("messages", MODE_PRIVATE);etup.setText(preferences.getString("msg_up","1"));etdown.setText(preferences.getString("msg_down","3"));etleft.setText(preferences.getString("msg_left","4"));etright.setText(preferences.getString("msg_right","2"));etmsh.setText(preferences.getString("msg_msh","0"));etmlg.setText(preferences.getString("msg_mlg","5"));etmup.setText(preferences.getString("msg_mup","6"));etring.setText(preferences.getString("msg_ring","0"));}public void SaveOnClick(View Source) {SharedPreferences preferences = getSharedPreferences("messages", MODE_PRIVATE);SharedPreferences.Editor editor = preferences.edit();editor.putString("msg_up",etup.getText().toString());editor.putString("msg_down",etdown.getText().toString());editor.putString("msg_left",etleft.getText().toString());editor.putString("msg_right",etright.getText().toString());editor.putString("msg_msh",etmsh.getText().toString());editor.putString("msg_mlg",etmlg.getText().toString());editor.putString("msg_mup",etmup.getText().toString());editor.putString("msg_ring",etring.getText().toString());editor.apply();// Close SettingsActivityfinish();}
}

五、主界面布局

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context="com.example.z.buletoothdemo.MainActivity"><TextViewandroid:id="@+id/tv_con_dev"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/con_dev"android:textAppearance="?android:attr/textAppearanceMedium" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><Buttonandroid:id="@+id/btn_dev_name"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="9"android:background="@drawable/btn_line"android:gravity="start|center_vertical"android:onClick="ChooseDevOnClick"android:text="@string/dev_name" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:background="@drawable/bg_button"android:onClick="SearchOnClick"android:text="@string/dots"android:textColor="@color/white" /></LinearLayout><RelativeLayoutandroid:layout_width="300dp"android:layout_height="300dp"android:layout_gravity="center_horizontal"android:layout_marginBottom="30dp"android:layout_marginTop="50dp"><ImageViewandroid:layout_width="300dp"android:layout_height="300dp"android:layout_centerHorizontal="true"android:layout_centerVertical="true"android:contentDescription="@string/app_name"android:src="@drawable/shp_around" /><Buttonandroid:id="@+id/btn_mid"android:layout_width="150dp"android:layout_height="150dp"android:layout_centerHorizontal="true"android:layout_centerVertical="true"android:background="@drawable/btn_mid"/><Buttonandroid:id="@+id/btn_up"android:layout_width="50dp"android:layout_height="wrap_content"android:layout_above="@id/btn_mid"android:layout_centerHorizontal="true"android:background="@drawable/btn_up"android:onClick="UpOnClick" /><Buttonandroid:id="@+id/btn_down"android:layout_width="50dp"android:layout_height="wrap_content"android:layout_below="@id/btn_mid"android:layout_centerHorizontal="true"android:background="@drawable/btn_down"android:onClick="DownOnClick" /><Buttonandroid:id="@+id/btn_left"android:layout_width="50dp"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_toLeftOf="@id/btn_mid"android:layout_toStartOf="@id/btn_mid"android:background="@drawable/btn_left"android:onClick="LeftOnClick" /><Buttonandroid:id="@+id/btn_right"android:layout_width="50dp"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_toEndOf="@id/btn_mid"android:layout_toRightOf="@id/btn_mid"android:background="@drawable/btn_right"android:onClick="RightOnClick" /></RelativeLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><EditTextandroid:id="@+id/et_message"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="9"android:hint="@string/h_message"android:maxLength="32"/><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:background="@drawable/bg_button"android:onClick="BtnSendOnClick"android:text="@string/send"android:textColor="@color/white" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><Buttonandroid:id="@+id/btn_settings"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:text="@string/settings"android:onClick="SettingsOnClick"/><Buttonandroid:id="@+id/btn_exit"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:onClick="ExitOnClick"android:text="@string/exit" /></LinearLayout>
</LinearLayout>

六、设置界面布局

activity_settings.xml

<?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"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:layout_weight="7"android:background="@color/colorPrimaryLight"android:text="@string/up"/><EditTextandroid:id="@+id/et_up"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="3"android:hint="@string/h_up"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:layout_weight="7"android:background="@color/colorPrimaryLight"android:text="@string/down"/><EditTextandroid:id="@+id/et_down"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="3"android:hint="@string/h_down"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:layout_weight="7"android:background="@color/colorPrimaryLight"android:text="@string/left"/><EditTextandroid:id="@+id/et_left"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="3"android:hint="@string/h_left"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:layout_weight="7"android:background="@color/colorPrimaryLight"android:text="@string/right"/><EditTextandroid:id="@+id/et_right"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="3"android:hint="@string/h_right"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:layout_weight="7"android:background="@color/colorPrimaryLight"android:text="@string/mid_sh"/><EditTextandroid:id="@+id/et_msh"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="3"android:hint="@string/h_mid_sh"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:layout_weight="7"android:background="@color/colorPrimaryLight"android:text="@string/mid_lg"/><EditTextandroid:id="@+id/et_mlg"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="3"android:hint="@string/h_mid_lg"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:layout_weight="7"android:background="@color/colorPrimaryLight"android:text="@string/mid_up"/><EditTextandroid:id="@+id/et_mup"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="3"android:hint="@string/h_mid_up"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:layout_weight="7"android:background="@color/colorPrimaryLight"android:text="@string/call_ring"/><EditTextandroid:id="@+id/et_ring"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="3"android:hint="@string/h_ring"/></LinearLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/bg_button"android:text="@string/save"android:textColor="@color/white"android:layout_alignParentBottom="true"android:layout_alignParentRight="true"android:layout_alignParentEnd="true"android:layout_margin="25sp"android:onClick="SaveOnClick"/></RelativeLayout>
</LinearLayout>

七、strings.xml

<resources><string name="app_name">BluetoothUnv</string><string name="con_dev">CONNECTED DEVICE:</string><string name="dev_name">(PLEASE CHOOSE)</string><string name="settings">SETTINGS</string><string name="exit">EXIT</string><string name="send">SEND</string><string name="save">SAVE</string><string name="dots">...</string><string name="h_message">32 CHARACTERS LIMITED </string><string name="dev_nsup_bt">Device does not support Bluetooth</string><string name="con_fail">(CONNECTION FAILED)</string><string name="choose_bt_dev">CHOOSE BLUETOOTH DEVICE</string><string name="up"    >UP</string><string name="down"  >DOWN</string><string name="left"  >LEFT</string><string name="right" >RIGHT</string><string name="mid_sh">MID-CLICK</string><string name="mid_lg">MID-PRESS</string><string name="mid_up">MID-RELEASE</string><string name="call_ring">CALL_RINGING</string><string name="h_up">default "1"</string><string name="h_down">default "3"</string><string name="h_left">default "4"</string><string name="h_right">default "2"</string><string name="h_mid_sh">default "0"</string><string name="h_mid_lg">default "5"</string><string name="h_mid_up">default "6"</string><string name="h_ring">default "0"</string>
</resources>

八、AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.z.buletoothdemo"><uses-permission android:name="android.permission.BLUETOOTH"/><uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/><!-- 允许读取手机状态的权限 --><uses-permission android:name="android.permission.READ_PHONE_STATE" /><applicationandroid:allowBackup="true"android:icon="@drawable/icon_launcher"android:label="@string/app_name"android:supportsRtl="true"android:theme="@style/AppTheme"><activityandroid:name=".MainActivity"android:label="@string/app_name"android:theme="@style/AppTheme.NoActionBar"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activityandroid:name=".SettingsActivity"android:label="@string/settings"></activity></application></manifest>

九、其他res

包括drawable文件夹中的一些.xml和.png,values文件夹下的colors.xml、dimens.xml和styles.xml,等。

十、代码下载

本项目代码已上传至“CODE”,地址:

https://code.csdn.net/sinat_30685475/bluetoothunv/tree/master

已上传至“下载”,地址:

http://download.csdn.net/detail/sinat_30685475/9595483

Android开发-蓝牙遥控器(字符串形式发送)-应用例程相关推荐

  1. Android开发——蓝牙通信实现

    Android开发--蓝牙通信实现 项目需求 项目主要代码及功能实现 AndroidManifest.xml res/values/string.xml activity_main.xml ChatS ...

  2. android 拨打电话 发送短信 权限,Android开发实现拨打电话与发送信息的方法分析...

    本文实例讲述了Android开发实现拨打电话与发送信息的方法.分享给大家供大家参考,具体如下: xml布局: android:layout_width="fill_parent" ...

  3. android开发蓝牙传输图片,如何发送/接收文本和图片通过蓝牙android到另一个android手机...

    我假设你已经在开发Android的蓝牙应用的经验. Android蓝牙API不直接支持OBEX,意味着我无法将任何文件直接推送到任何设备. Android蓝牙API提供诸如发现,连接和使用流的数据传输 ...

  4. Android 手机蓝牙遥控器解决方案

    驱动力(需求): 女朋友觉得躺床上用ipad看电视剧不爽,对睡姿要求太高,还容易砸到自己,所以提出需求,没辙,搞起来: 现有设备: Rk3288 开发版一个,dell 显示器一个,小音箱一对: 思路: ...

  5. android开发蓝牙是否可见开关_如何从后台开启android蓝牙的可见性以及始终保持可见性...

    最近工作中遇到一个特殊的需求,要求代码能够从后台开机android手机蓝牙的可见性.而framework提供了一种打开可见性的操作,就是通过向用户弹出一个提示框,来询问是否允许开启可见性.而且限制了最 ...

  6. Android开发蓝牙与ble设备的通讯

    一.写在前面的话 一直想写一篇关于蓝牙与ble设备通讯的博客,但是一直也不知道从何下手,可能是之前思路不清晰吧,也就一直拖拖拖,拖到现在.最近又做到关于ble设备的项目了,在此总结一下吧.(如有不到位 ...

  7. Android开发--蓝牙操作

    首先,由于模拟器上没有蓝牙装置,所以我们需要一个含有蓝牙装置的Android系统 其次,要操作设备上的蓝牙装置,需要在AndroidManifest中声明两个权限: <uses-permissi ...

  8. android开发蓝牙是否可见开关_android开发之蓝牙初步 扫描已配对蓝牙、更改蓝牙可见性、搜索外部蓝牙设备 | 学步园...

    这两天我学习了android蓝牙的一些简单操作,今天和大家分享一下. 一,获得BluetoothAdapter对象 BluetoothAdapter adapter = BluetoothAdapte ...

  9. Android开发蓝牙操作

    一.打开蓝牙权限 操作蓝牙之前必须先要注册蓝牙权限.在AndroidManifest.xml文件中注册权限: <uses-permission android:name="androi ...

最新文章

  1. 计算机视觉>>PCV安装和使用
  2. Amazon S3 功能介绍
  3. hutool中的threadutil_Hutool - 好用的Java工具类库
  4. SqlServer用户数据库的系统视图sysobjects、syscolumns、systypes
  5. 软件自动更新解决方案及QT实现
  6. 一个小例子对多态简单的理解
  7. 快照隔离(Snapshot Isolation)简单介绍和例子
  8. 机器学习十大经典算法——随机森林
  9. 蓝桥杯基础练习 杨辉三角形Python实现
  10. R矩形树状图 treemap
  11. 网络对时服务器(NTP校时服务器)应用港口信息化系统
  12. 一文纵览无监督学习研究现状:从自编码器到生成对抗网络
  13. Linux中pts/0的讲解
  14. 关于S参数的一些理解
  15. shiny-server部署
  16. 我的世界:命名牌暗藏众多彩蛋,老玩家:原来还能这样玩啊!
  17. Cache poisoning
  18. Qt QSS QSlider样式
  19. 孟岩大大《理解矩阵一二三》语录
  20. DataWorks值班表

热门文章

  1. 离线地图开发之模拟迁徙(含源代码)
  2. 代码复杂度分析——时间、空间复杂度
  3. 机甲大师机器人控制(一):概念与流程
  4. (五十二):多模态情感分析研究综述_张亚洲
  5. 王家卫入股的“导演合伙人制”,会给中国电影制造惊喜吗?
  6. Hutool - 对于网络的一些方法和增强
  7. 挂茶馆VIP问道教程
  8. 盛大是中国互联网最耀眼的流星
  9. 发现好文!51单片机特殊功能寄存器 /I/O口操作 /中断/ 定时器/ 串口通信/ ---位寻址解释由来--以及程序例程
  10. 这两他安搬家,今天终于搬完了!