資源簡介
BluetoothChat 藍(lán)牙聊天 Android 官方源碼 帶注釋 只用了3個java文件實行了藍(lán)牙聊天,代碼簡單易懂

代碼片段和文件信息
/*
?*?Copyright?(C)?2009?The?Android?Open?Source?Project
?*
?*?Licensed?under?the?Apache?License?Version?2.0?(the?“License“);
?*?you?may?not?use?this?file?except?in?compliance?with?the?License.
?*?You?may?obtain?a?copy?of?the?License?at
?*
?*??????http://www.apache.org/licenses/LICENSE-2.0
?*
?*?Unless?required?by?applicable?law?or?agreed?to?in?writing?software
?*?distributed?under?the?License?is?distributed?on?an?“AS?IS“?BASIS
?*?WITHOUT?WARRANTIES?OR?CONDITIONS?OF?ANY?KIND?either?express?or?implied.
?*?See?the?License?for?the?specific?language?governing?permissions?and
?*?limitations?under?the?License.
?*/
package?com.example.android.BluetoothChat;
import?android.app.Activity;
import?android.bluetooth.BluetoothAdapter;
import?android.bluetooth.BluetoothDevice;
import?android.content.Intent;
import?android.os.Bundle;
import?android.os.Handler;
import?android.os.Message;
import?android.util.Log;
import?android.view.KeyEvent;
import?android.view.Menu;
import?android.view.MenuInflater;
import?android.view.MenuItem;
import?android.view.View;
import?android.view.Window;
import?android.view.View.onclickListener;
import?android.view.inputmethod.EditorInfo;
import?android.widget.ArrayAdapter;
import?android.widget.Button;
import?android.widget.EditText;
import?android.widget.ListView;
import?android.widget.TextView;
import?android.widget.Toast;
/**
?*?This?is?the?main?Activity?that?displays?the?current?chat?session.
?*/
public?class?BluetoothChat?extends?Activity?{
????//?Debugging
????private?static?final?String?TAG?=?“BluetoothChat“;
????private?static?final?boolean?D?=?true;
????//?Message?types?sent?from?the?BluetoothChatService?Handler
????public?static?final?int?MESSAGE_STATE_CHANGE?=?1;
????public?static?final?int?MESSAGE_READ?=?2;
????public?static?final?int?MESSAGE_WRITE?=?3;
????public?static?final?int?MESSAGE_DEVICE_NAME?=?4;
????public?static?final?int?MESSAGE_TOAST?=?5;
????//?Key?names?received?from?the?BluetoothChatService?Handler
????public?static?final?String?DEVICE_NAME?=?“device_name“;
????public?static?final?String?TOAST?=?“toast“;
????//?Intent?request?codes
????private?static?final?int?REQUEST_CONNECT_DEVICE?=?1;
????private?static?final?int?REQUEST_ENABLE_BT?=?2;
????//?Layout?Views
????private?TextView?mtitle;
????private?ListView?mConversationView;
????private?EditText?mOutEditText;
????private?Button?mSendButton;
????//?Name?of?the?connected?device
????private?String?mConnectedDeviceName?=?null;
????//?Array?adapter?for?the?conversation?thread
????private?ArrayAdapter?mConversationArrayAdapter;
????//?String?buffer?for?outgoing?messages
????private?StringBuffer?mOutStringBuffer;
????//?Local?Bluetooth?adapter
????private?BluetoothAdapter?mBluetoothAdapter?=?null;
????//?Member?object?for?the?chat?services
????private?BluetoothChatService?mChatService?=?null;
????@Override
????public?void?onCreate(Bundle?savedInstanceState)?{
????????super.onCreate(savedInstanceState);
????????if(D)?Log.e(TAG?“+++?ON?CREAT
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1799??2010-08-08?15:20??BluetoothChat\BluetoothChat\AndroidManifest.xm
?????文件???????4182??2010-08-08?15:20??BluetoothChat\BluetoothChat\res\drawable\app_icon.png
?????文件???????5589??2010-08-08?15:20??BluetoothChat\BluetoothChat\res\drawable-hdpi\app_icon.png
?????文件???????1532??2010-08-08?15:20??BluetoothChat\BluetoothChat\res\layout\custom_ti
?????文件???????2158??2010-08-08?15:20??BluetoothChat\BluetoothChat\res\layout\device_list.xm
?????文件????????876??2010-08-08?15:20??BluetoothChat\BluetoothChat\res\layout\device_name.xm
?????文件???????1744??2010-08-08?15:20??BluetoothChat\BluetoothChat\res\layout\main.xm
?????文件????????876??2010-08-08?15:20??BluetoothChat\BluetoothChat\res\layout\message.xm
?????文件???????1033??2010-08-08?15:20??BluetoothChat\BluetoothChat\res\menu\option_menu.xm
?????文件???????1793??2010-08-08?15:20??BluetoothChat\BluetoothChat\res\values\strings.xm
?????文件??????13147??2010-08-08?15:20??BluetoothChat\BluetoothChat\src\com\example\android\BluetoothChat\BluetoothChat.java
?????文件??????15570??2010-08-08?15:20??BluetoothChat\BluetoothChat\src\com\example\android\BluetoothChat\BluetoothChatService.java
?????文件???????7958??2010-08-08?15:20??BluetoothChat\BluetoothChat\src\com\example\android\BluetoothChat\DeviceListActivity.java
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat\src\com\example\android\BluetoothChat
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat\src\com\example\android
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat\src\com\example
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat\res\drawable
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat\res\drawable-hdpi
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat\res\layout
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat\res\menu
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat\res\values
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat\src\com
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat\res
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat\src
?????目錄??????????0??2010-11-30?18:34??BluetoothChat\BluetoothChat
?????目錄??????????0??2010-11-30?18:34??BluetoothChat
-----------?---------??----------?-----??----
????????????????58257????????????????????26
評論
共有 條評論