app.akexorcist.bluetotohspp.library.BluetoothSPP Java Examples

The following examples show how to use app.akexorcist.bluetotohspp.library.BluetoothSPP. 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 File: BTService.java    From Chorus-RF-Laptimer with MIT License 6 votes vote down vote up
@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);
        }
    });
}
 
Example #2
Source File: DeviceListActivity.java    From BluetoothSPPLibrary with Apache License 2.0 5 votes vote down vote up
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 #3
Source File: BTService.java    From Chorus-RF-Laptimer with MIT License 4 votes vote down vote up
BTService(Context context, byte delimiter) {
    mBT = new BluetoothSPP(context, delimiter);
}
 
Example #4
Source File: BTService.java    From Chorus-RF-Laptimer with MIT License 4 votes vote down vote up
void setDataReceiveListener(BluetoothSPP.OnDataReceivedListener listener) {
    mBT.setOnDataReceivedListener(listener);
}
 
Example #5
Source File: BTService.java    From Chorus-RF-Laptimer with MIT License 4 votes vote down vote up
void setConnectionListener(BluetoothSPP.BluetoothConnectionListener listener) {
    mBT.setBluetoothConnectionListener(listener);
}
 
Example #6
Source File: BluetoothManager.java    From Droid2JoyStick with Apache License 2.0 4 votes vote down vote up
public BluetoothManager(Context context) {
    bt = new BluetoothSPP(context);
}
 
Example #7
Source File: SimpleActivity.java    From BluetoothSPPLibrary with Apache License 2.0 4 votes vote down vote up
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); 
       		}
       	}
       }); 
}
 
Example #8
Source File: TerminalActivity.java    From BluetoothSPPLibrary with Apache License 2.0 4 votes vote down vote up
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_terminal);
    Log.i("Check", "onCreate");

    textRead = (TextView)findViewById(R.id.textRead);
    textStatus = (TextView)findViewById(R.id.textStatus);
    etMessage = (EditText)findViewById(R.id.etMessage);

    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) {
            textRead.append(message + "\n");
        }
    });

    bt.setBluetoothConnectionListener(new BluetoothConnectionListener() {
        public void onDeviceDisconnected() {
            textStatus.setText("Status : Not connect");
            menu.clear();
            getMenuInflater().inflate(R.menu.menu_connection, menu);
        }

        public void onDeviceConnectionFailed() {
            textStatus.setText("Status : Connection failed");
        }

        public void onDeviceConnected(String name, String address) {
            textStatus.setText("Status : Connected to " + name);
            menu.clear();
            getMenuInflater().inflate(R.menu.menu_disconnection, menu);
        }
    });
}