本文整理汇总了Java中app.akexorcist.bluetotohspp.library.BluetoothSPP类的典型用法代码示例。如果您正苦于以下问题:Java BluetoothSPP类的具体用法?Java BluetoothSPP怎么用?Java BluetoothSPP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BluetoothSPP类属于app.akexorcist.bluetotohspp.library包,在下文中一共展示了BluetoothSPP类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setConnectionListener
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
@Override
public void setConnectionListener(final ConnectionListener listener) {
mBT.setBluetoothConnectionListener(new BluetoothSPP.BluetoothConnectionListener() {
@Override
public void onDeviceConnected(String name, String address) {
listener.onConnected(name);
}
@Override
public void onDeviceDisconnected() {
listener.onDisconnected();
}
@Override
public void onDeviceConnectionFailed() {
listener.onConnectionFailed("");
}
});
mBT.setOnDataReceivedListener(new BluetoothSPP.OnDataReceivedListener() {
@Override
public void onDataReceived(byte[] data, String message) {
listener.onDataReceived(message);
}
});
}
开发者ID:voroshkov,项目名称:Chorus-RF-Laptimer,代码行数:27,代码来源:BTService.java
示例2: connect
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
private void connect() {
if ( bluetoothSPP.isBluetoothEnabled() && bluetoothSPP.isBluetoothAvailable() ) {
if ( !bluetoothSPP.isServiceAvailable() ) {
bluetoothSPP.setupService();
bluetoothSPP.startService( BluetoothState.DEVICE_OTHER );
}
if ( bluetoothSPP.isServiceAvailable() ) {
Log.v( TAG, "+++ Connecting device +++" );
bluetoothSPP.setAutoConnectionListener( new BluetoothSPP.AutoConnectionListener() {
@Override
public void onAutoConnectionStarted() {
Log.v( TAG, "+++ Bluetooth device connected +++" );
}
@Override
public void onNewConnection( final String name, final String address ) {
Log.v( TAG, "+++ New connection on '" + name + " :: " + address + "' +++" );
}
} );
bluetoothSPP.autoConnect( "SPP-" );
bluetoothSPP.setOnDataReceivedListener( new BluetoothSPP.OnDataReceivedListener() {
public void onDataReceived( byte[] data, String message ) {
// Do something when data incoming
userFeedback.alert( message );
}
} );
}
} else {
userFeedback.error( "Connect and enable bluetooth!" );
return;
}
}
开发者ID:IstraTech,项目名称:bixolon-driver,代码行数:41,代码来源:BluetoothBixolonActivity.java
示例3: setBluetoothListeners
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
private void setBluetoothListeners() {
BluetoothSPP.getInstance().setOnDataReceivedListener(new BluetoothSPP.OnDataReceivedListener() {
@Override
public void onDataReceived(byte[] data, String msg) {
try {
Log.d(TAG, "Data received (Bluetooth): " + msg);
onBluetoothString(msg);
Gson gson = new Gson();
final NanoPlayBoardMessage message = gson.fromJson(msg, NanoPlayBoardMessage.class);
onBluetoothMessage(message);
} catch (JsonSyntaxException jse) {
jse.printStackTrace();
}
}
});
}
开发者ID:josejuansanchez,项目名称:NanoPlayBoard-Android-App,代码行数:18,代码来源:NanoPlayBoardActivity.java
示例4: sendJsonMessage
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
protected void sendJsonMessage(NanoPlayBoardMessage message) {
Gson gson = new GsonBuilder().registerTypeHierarchyAdapter(
Collection.class, new CollectionAdapter()).create();
Log.d(TAG, "JSON: " + gson.toJson(message));
// if UsbService was correctly binded, send data
if (mUsbService != null) {
mUsbService.write(gson.toJson(message).getBytes());
mUsbService.write("\n".getBytes());
}
// if Bluetooth service is correctly connected, send data
if (BluetoothSPP.getInstance().isServiceAvailable()) {
BluetoothSPP.getInstance().send(gson.toJson(message).getBytes(), false);
BluetoothSPP.getInstance().send("\n".getBytes(), false);
}
}
开发者ID:josejuansanchez,项目名称:NanoPlayBoard-Android-App,代码行数:19,代码来源:NanoPlayBoardActivity.java
示例5: loadBluetoothListeners
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
private void loadBluetoothListeners() {
BluetoothSPP.getInstance().setBluetoothConnectionListener(new BluetoothSPP.BluetoothConnectionListener() {
public void onDeviceDisconnected() {
mMenu.clear();
Snackbar.make(mListview, R.string.bluetooth_status_disconnected, Snackbar.LENGTH_LONG).show();
}
public void onDeviceConnectionFailed() {
Snackbar.make(mListview, R.string.bluetooth_status_failed, Snackbar.LENGTH_LONG).show();
}
public void onDeviceConnected(String name, String address) {
mMenu.clear();
getMenuInflater().inflate(R.menu.menu_bluetooth_disconnection, mMenu);
Snackbar.make(mListview, getString(R.string.bluetooth_status_connected) + name, Snackbar.LENGTH_LONG).show();
}
});
}
开发者ID:josejuansanchez,项目名称:NanoPlayBoard-Android-App,代码行数:20,代码来源:ListViewActivity.java
示例6: loadBluetoothListeners
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
private void loadBluetoothListeners() {
BluetoothSPP.getInstance().setBluetoothConnectionListener(new BluetoothSPP.BluetoothConnectionListener() {
public void onDeviceDisconnected() {
mMenu.clear();
Snackbar.make(mRecyclerView, R.string.bluetooth_status_disconnected, Snackbar.LENGTH_LONG).show();
}
public void onDeviceConnectionFailed() {
Snackbar.make(mRecyclerView, R.string.bluetooth_status_failed, Snackbar.LENGTH_LONG).show();
}
public void onDeviceConnected(String name, String address) {
mMenu.clear();
getMenuInflater().inflate(R.menu.menu_bluetooth_disconnection, mMenu);
Snackbar.make(mRecyclerView, getString(R.string.bluetooth_status_connected) + name, Snackbar.LENGTH_LONG).show();
}
});
}
开发者ID:josejuansanchez,项目名称:NanoPlayBoard-Android-App,代码行数:19,代码来源:RecyclerViewActivity.java
示例7: sendString
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
protected void sendString(String data) {
// if UsbService was correctly binded, send data
if (mUsbService != null) {
mUsbService.write(data.getBytes());
mUsbService.write("\n".getBytes());
}
// if Bluetooth service is correctly connected, send data
if (BluetoothSPP.getInstance().isServiceAvailable()) {
BluetoothSPP.getInstance().send(data.getBytes(), false);
BluetoothSPP.getInstance().send("\n".getBytes(), false);
}
}
开发者ID:josejuansanchez,项目名称:NanoPlayBoard-Android-App,代码行数:14,代码来源:NanoPlayBoardActivity.java
示例8: onActivityResult
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == BluetoothState.REQUEST_CONNECT_DEVICE) {
if(resultCode == Activity.RESULT_OK)
BluetoothSPP.getInstance().connect(data);
} else if(requestCode == BluetoothState.REQUEST_ENABLE_BT) {
if(resultCode == Activity.RESULT_OK) {
BluetoothSPP.getInstance().setupService();
BluetoothSPP.getInstance().setDeviceTarget(BluetoothState.DEVICE_OTHER);
Intent intent = new Intent(getApplicationContext(), DeviceList.class);
startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
} else {
Snackbar.make(mListview, R.string.bluetooth_status_not_enabled, Snackbar.LENGTH_LONG).show();
}
}
}
开发者ID:josejuansanchez,项目名称:NanoPlayBoard-Android-App,代码行数:16,代码来源:ListViewActivity.java
示例9: onActivityResult
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == BluetoothState.REQUEST_CONNECT_DEVICE) {
if(resultCode == Activity.RESULT_OK)
BluetoothSPP.getInstance().connect(data);
} else if(requestCode == BluetoothState.REQUEST_ENABLE_BT) {
if(resultCode == Activity.RESULT_OK) {
BluetoothSPP.getInstance().setupService();
BluetoothSPP.getInstance().setDeviceTarget(BluetoothState.DEVICE_OTHER);
Intent intent = new Intent(getApplicationContext(), DeviceList.class);
startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
} else {
Snackbar.make(mRecyclerView, R.string.bluetooth_status_not_enabled, Snackbar.LENGTH_LONG).show();
}
}
}
开发者ID:josejuansanchez,项目名称:NanoPlayBoard-Android-App,代码行数:16,代码来源:RecyclerViewActivity.java
示例10: onCreate
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
}
Fabric.with(this, new Crashlytics());
EventBus.getDefault().register(this);
prefs = new Prefs(this);
prefs.setChangeListener(this);
packageName = this.getPackageName();
Timber.d("current version: " + prefs.getVersion());
Timber.d("new version: "+VERSION);
if(prefs.getVersion() < VERSION) {
setup();
}
bt = new BluetoothSPP(this);
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
this.registerReceiver(broadcastReceiver, filter);
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(null==bluetoothAdapter) {
EventBus.getDefault().postSticky(new BluetoothEvent(BluetoothAdapter.STATE_OFF));
} else {
EventBus.getDefault().postSticky(new BluetoothEvent(bluetoothAdapter.getState()));
}
bt.setOnDataReceivedListener(new BluetoothSPP.OnDataReceivedListener() {
public void onDataReceived(byte[] data, String message) {
ToastEvent.toast("Recieved data");
Timber.d("Recieved data");
Timber.d(message);
AsyncExecutor.create().execute(new BluetoothImportJson(OurAlliance.this,message));
}
});
EventBus.getDefault().postSticky(bt);
// new AlarmTheBlueAlliance(this.getApplicationContext()).setAlarm();
}
开发者ID:mechinn,项目名称:our-alliance-android,代码行数:39,代码来源:OurAlliance.java
示例11: onCreate
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_devicelist);
bt = new BluetoothSPP(this);
if(!bt.isBluetoothAvailable()) {
Toast.makeText(getApplicationContext()
, "Bluetooth is not available"
, Toast.LENGTH_SHORT).show();
finish();
}
bt.setOnDataReceivedListener(new OnDataReceivedListener() {
public void onDataReceived(byte[] data, String message) {
Log.i("Check", "Length : " + data.length);
Log.i("Check", "Message : " + message);
}
});
Button btnConnect = (Button)findViewById(R.id.btnConnect);
btnConnect.setOnClickListener(new OnClickListener(){
public void onClick(View v){
if(bt.getServiceState() == BluetoothState.STATE_CONNECTED) {
bt.disconnect();
} else {
Intent intent = new Intent(DeviceListActivity.this, DeviceList.class);
intent.putExtra("bluetooth_devices", "Bluetooth devices");
intent.putExtra("no_devices_found", "No device");
intent.putExtra("scanning", "Scanning");
intent.putExtra("scan_for_devices", "Search");
intent.putExtra("select_device", "Select");
intent.putExtra("layout_list", R.layout.device_layout_list);
intent.putExtra("layout_text", R.layout.device_layout_text);
startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
}
}
});
}
开发者ID:akexorcist,项目名称:Android-BluetoothSPPLibrary,代码行数:40,代码来源:DeviceListActivity.java
示例12: BTService
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
BTService(Context context, byte delimiter) {
mBT = new BluetoothSPP(context, delimiter);
}
开发者ID:voroshkov,项目名称:Chorus-RF-Laptimer,代码行数:4,代码来源:BTService.java
示例13: setDataReceiveListener
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
void setDataReceiveListener(BluetoothSPP.OnDataReceivedListener listener) {
mBT.setOnDataReceivedListener(listener);
}
开发者ID:voroshkov,项目名称:Chorus-RF-Laptimer,代码行数:4,代码来源:BTService.java
示例14: BluetoothManager
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
public BluetoothManager(Context context) {
bt = new BluetoothSPP(context);
}
开发者ID:akexorcist,项目名称:Droid2JoyStick,代码行数:4,代码来源:BluetoothManager.java
示例15: onDestroy
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
@Override
protected void onDestroy() {
super.onDestroy();
BluetoothSPP.getInstance().stopService();
}
开发者ID:josejuansanchez,项目名称:NanoPlayBoard-Android-App,代码行数:6,代码来源:ListViewActivity.java
示例16: onCreate
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bluetooth);
mBT = new BluetoothSPP(this);
}
开发者ID:josejuansanchez,项目名称:NanoPlayBoard-Android-App,代码行数:7,代码来源:BluetoothActivity.java
示例17: ExportJsonEventMatchScouting2015
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
public ExportJsonEventMatchScouting2015(Context context, BluetoothSPP bluetooth) {
super(context, bluetooth);
}
开发者ID:mechinn,项目名称:our-alliance-android,代码行数:4,代码来源:ExportJsonEventMatchScouting2015.java
示例18: ExportJsonEventTeamScouting2015
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
public ExportJsonEventTeamScouting2015(Context context, BluetoothSPP bluetooth) {
super(context, bluetooth);
}
开发者ID:mechinn,项目名称:our-alliance-android,代码行数:4,代码来源:ExportJsonEventTeamScouting2015.java
示例19: ExportJson
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
public ExportJson(Context context, BluetoothSPP bluetooth) {
this.context = context;
this.prefs = new Prefs(context);
this.bluetooth = bluetooth;
json = "";
}
开发者ID:mechinn,项目名称:our-alliance-android,代码行数:7,代码来源:ExportJson.java
示例20: onCreate
import app.akexorcist.bluetotohspp.library.BluetoothSPP; //导入依赖的package包/类
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simple);
bt = new BluetoothSPP(this);
if(!bt.isBluetoothAvailable()) {
Toast.makeText(getApplicationContext()
, "Bluetooth is not available"
, Toast.LENGTH_SHORT).show();
finish();
}
bt.setOnDataReceivedListener(new OnDataReceivedListener() {
public void onDataReceived(byte[] data, String message) {
Toast.makeText(SimpleActivity.this, message, Toast.LENGTH_SHORT).show();
}
});
bt.setBluetoothConnectionListener(new BluetoothConnectionListener() {
public void onDeviceConnected(String name, String address) {
Toast.makeText(getApplicationContext()
, "Connected to " + name + "\n" + address
, Toast.LENGTH_SHORT).show();
}
public void onDeviceDisconnected() {
Toast.makeText(getApplicationContext()
, "Connection lost", Toast.LENGTH_SHORT).show();
}
public void onDeviceConnectionFailed() {
Toast.makeText(getApplicationContext()
, "Unable to connect", Toast.LENGTH_SHORT).show();
}
});
Button btnConnect = (Button)findViewById(R.id.btnConnect);
btnConnect.setOnClickListener(new OnClickListener(){
public void onClick(View v){
if(bt.getServiceState() == BluetoothState.STATE_CONNECTED) {
bt.disconnect();
} else {
Intent intent = new Intent(getApplicationContext(), DeviceList.class);
startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
}
}
});
}
开发者ID:akexorcist,项目名称:Android-BluetoothSPPLibrary,代码行数:50,代码来源:SimpleActivity.java
注:本文中的app.akexorcist.bluetotohspp.library.BluetoothSPP类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论