Java Code Examples for app.akexorcist.bluetotohspp.library.BluetoothSPP#isBluetoothAvailable()

The following examples show how to use app.akexorcist.bluetotohspp.library.BluetoothSPP#isBluetoothAvailable() . 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: 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 2
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 3
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);
        }
    });
}