app.akexorcist.bluetotohspp.library.BluetoothState Java Examples
The following examples show how to use
app.akexorcist.bluetotohspp.library.BluetoothState.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Chorus-RF-Laptimer Author: voroshkov File: MainActivity.java License: MIT License | 6 votes |
public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == BluetoothState.REQUEST_CONNECT_DEVICE) { if (resultCode == Activity.RESULT_OK) { bt.connect(data); useBT(); } } else if (requestCode == BluetoothState.REQUEST_ENABLE_BT) { if (resultCode == Activity.RESULT_OK) { bt.runService(); } else { Toast.makeText(getApplicationContext() , "Bluetooth was not enabled." , Toast.LENGTH_SHORT).show(); finish(); } } }
Example #2
Source Project: BluetoothSPPLibrary Author: akexorcist File: SimpleActivity.java License: Apache License 2.0 | 6 votes |
public void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == BluetoothState.REQUEST_CONNECT_DEVICE) { if(resultCode == Activity.RESULT_OK) bt.connect(data); } else if(requestCode == BluetoothState.REQUEST_ENABLE_BT) { if(resultCode == Activity.RESULT_OK) { bt.setupService(); bt.startService(BluetoothState.DEVICE_ANDROID); setup(); } else { Toast.makeText(getApplicationContext() , "Bluetooth was not enabled." , Toast.LENGTH_SHORT).show(); finish(); } } }
Example #3
Source Project: BluetoothSPPLibrary Author: akexorcist File: TerminalActivity.java License: Apache License 2.0 | 6 votes |
public void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == BluetoothState.REQUEST_CONNECT_DEVICE) { if(resultCode == Activity.RESULT_OK) bt.connect(data); } else if(requestCode == BluetoothState.REQUEST_ENABLE_BT) { if(resultCode == Activity.RESULT_OK) { bt.setupService(); bt.startService(BluetoothState.DEVICE_ANDROID); setup(); } else { Toast.makeText(getApplicationContext() , "Bluetooth was not enabled." , Toast.LENGTH_SHORT).show(); finish(); } } }
Example #4
Source Project: Chorus-RF-Laptimer Author: voroshkov File: MainActivity.java License: MIT License | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); Handler delayedDisconnect = new Handler() { public void handleMessage(Message msg) { if (AppState.getInstance().conn != null) { AppState.getInstance().conn.disconnect(); } } }; switch (id) { case R.id.menuBTConnect: bt.setDeviceTarget(BluetoothState.DEVICE_OTHER); Intent intent = new Intent(getApplicationContext(), DeviceList.class); startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE); break; case R.id.menuUDPConnect: preferWifiAndConnectUDP(); break; case R.id.menuUSBConnect: checkUSBPermissionsAndConnectIfAllowed(); break; case R.id.menuDisconnect: AppState.getInstance().onBeforeDisconnect(); delayedDisconnect.sendEmptyMessageDelayed(0, 100); break; } return super.onOptionsItemSelected(item); }
Example #5
Source Project: Droid2JoyStick Author: akexorcist File: MainActivity.java License: Apache License 2.0 | 5 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == BluetoothState.REQUEST_CONNECT_DEVICE) { if (resultCode == Activity.RESULT_OK) { BluetoothManager.getInstance().connect(data); } } else if (requestCode == BluetoothState.REQUEST_ENABLE_BT) { if (resultCode == Activity.RESULT_OK) { BluetoothManager.getInstance().setupService(); BluetoothManager.getInstance().startService(); } else { // Do something if user doesn't choose any device (Pressed back) } } }
Example #6
Source Project: BluetoothSPPLibrary Author: akexorcist File: SimpleActivity.java License: Apache License 2.0 | 5 votes |
public void onStart() { super.onStart(); if (!bt.isBluetoothEnabled()) { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(intent, BluetoothState.REQUEST_ENABLE_BT); } else { if(!bt.isServiceAvailable()) { bt.setupService(); bt.startService(BluetoothState.DEVICE_ANDROID); setup(); } } }
Example #7
Source Project: BluetoothSPPLibrary Author: akexorcist File: AutoConnectActivity.java License: Apache License 2.0 | 5 votes |
public void onStart() { super.onStart(); if(!bt.isBluetoothEnabled()) { bt.enable(); } else { if(!bt.isServiceAvailable()) { bt.setupService(); bt.startService(BluetoothState.DEVICE_OTHER); setup(); } } }
Example #8
Source Project: BluetoothSPPLibrary Author: akexorcist File: AutoConnectActivity.java License: Apache License 2.0 | 5 votes |
public void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == BluetoothState.REQUEST_CONNECT_DEVICE) { if(resultCode == Activity.RESULT_OK) bt.connect(data); } else if(requestCode == BluetoothState.REQUEST_ENABLE_BT) { if(resultCode == Activity.RESULT_OK) { bt.setupService(); } else { Toast.makeText(getApplicationContext() , "Bluetooth was not enabled." , Toast.LENGTH_SHORT).show(); finish(); } } }
Example #9
Source Project: BluetoothSPPLibrary Author: akexorcist File: ListenerActivity.java License: Apache License 2.0 | 5 votes |
public void onStart() { super.onStart(); if(!bt.isBluetoothEnabled()) { bt.enable(); } else { if(!bt.isServiceAvailable()) { bt.setupService(); bt.startService(BluetoothState.DEVICE_ANDROID); setup(); } } }
Example #10
Source Project: BluetoothSPPLibrary Author: akexorcist File: ListenerActivity.java License: Apache License 2.0 | 5 votes |
public void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == BluetoothState.REQUEST_CONNECT_DEVICE) { if(resultCode == Activity.RESULT_OK) bt.connect(data); } else if(requestCode == BluetoothState.REQUEST_ENABLE_BT) { if(resultCode == Activity.RESULT_OK) { bt.setupService(); } else { Toast.makeText(getApplicationContext() , "Bluetooth was not enabled." , Toast.LENGTH_SHORT).show(); finish(); } } }
Example #11
Source Project: BluetoothSPPLibrary Author: akexorcist File: DeviceListActivity.java License: Apache License 2.0 | 5 votes |
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); } } }); }
Example #12
Source Project: BluetoothSPPLibrary Author: akexorcist File: DeviceListActivity.java License: Apache License 2.0 | 5 votes |
public void onStart() { super.onStart(); if(!bt.isBluetoothEnabled()) { bt.enable(); } else { if(!bt.isServiceAvailable()) { bt.setupService(); bt.startService(BluetoothState.DEVICE_ANDROID); setup(); } } }
Example #13
Source Project: BluetoothSPPLibrary Author: akexorcist File: DeviceListActivity.java License: Apache License 2.0 | 5 votes |
public void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == BluetoothState.REQUEST_CONNECT_DEVICE) { if(resultCode == Activity.RESULT_OK) bt.connect(data); } else if(requestCode == BluetoothState.REQUEST_ENABLE_BT) { if(resultCode == Activity.RESULT_OK) { bt.setupService(); } else { Toast.makeText(getApplicationContext() , "Bluetooth was not enabled." , Toast.LENGTH_SHORT).show(); finish(); } } }
Example #14
Source Project: BluetoothSPPLibrary Author: akexorcist File: TerminalActivity.java License: Apache License 2.0 | 5 votes |
public void onStart() { super.onStart(); if (!bt.isBluetoothEnabled()) { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(intent, BluetoothState.REQUEST_ENABLE_BT); } else { if(!bt.isServiceAvailable()) { bt.setupService(); bt.startService(BluetoothState.DEVICE_ANDROID); setup(); } } }
Example #15
Source Project: Chorus-RF-Laptimer Author: voroshkov File: BTService.java License: MIT License | 4 votes |
void runService() { mBT.setupService(); mBT.startService(BluetoothState.DEVICE_OTHER); }
Example #16
Source Project: Droid2JoyStick Author: akexorcist File: BluetoothManager.java License: Apache License 2.0 | 4 votes |
public void openBluetoothConnection(Activity activity) { Intent intent = new Intent(activity, DeviceList.class); activity.startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE); }
Example #17
Source Project: BluetoothSPPLibrary Author: akexorcist File: SimpleActivity.java License: Apache License 2.0 | 4 votes |
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); } } }); }