|
|
@ -11,6 +11,7 @@ import android.content.IntentFilter; |
|
|
import android.content.ServiceConnection; |
|
|
import android.content.ServiceConnection; |
|
|
import android.os.IBinder; |
|
|
import android.os.IBinder; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
|
|
|
import android.provider.SyncStateContract; |
|
|
import android.util.Log; |
|
|
import android.util.Log; |
|
|
import android.view.MenuItem; |
|
|
import android.view.MenuItem; |
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
@ -26,6 +27,7 @@ public class SimpleDetailActivity extends Activity { |
|
|
private TextView mConnectionStateView; |
|
|
private TextView mConnectionStateView; |
|
|
private TextView mSensorValueView; |
|
|
private TextView mSensorValueView; |
|
|
private TextView mWritableValueView; |
|
|
private TextView mWritableValueView; |
|
|
|
|
|
private TextView mFormView; |
|
|
|
|
|
|
|
|
private String mDeviceName; |
|
|
private String mDeviceName; |
|
|
private String mDeviceAddress; |
|
|
private String mDeviceAddress; |
|
|
@ -113,6 +115,7 @@ public class SimpleDetailActivity extends Activity { |
|
|
mDeviceAddressView = (TextView) findViewById(R.id.device_address); |
|
|
mDeviceAddressView = (TextView) findViewById(R.id.device_address); |
|
|
mDeviceAddressView.setText(mDeviceAddress); |
|
|
mDeviceAddressView.setText(mDeviceAddress); |
|
|
|
|
|
|
|
|
|
|
|
mFormView = (TextView) findViewById(R.id.form_view); |
|
|
mConnectionStateView = (TextView) findViewById(R.id.connection_state); |
|
|
mConnectionStateView = (TextView) findViewById(R.id.connection_state); |
|
|
mSensorValueView = (TextView) findViewById(R.id.sensor_value); |
|
|
mSensorValueView = (TextView) findViewById(R.id.sensor_value); |
|
|
mWritableValueView = (TextView) findViewById(R.id.writable_value); |
|
|
mWritableValueView = (TextView) findViewById(R.id.writable_value); |
|
|
@ -209,6 +212,18 @@ public class SimpleDetailActivity extends Activity { |
|
|
requestWritableValue(); |
|
|
requestWritableValue(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onSendClick(View view) { |
|
|
|
|
|
Log.d(TAG, "onSendClick()"); |
|
|
|
|
|
byte [] text = mFormView.getText().toString().getBytes(); |
|
|
|
|
|
byte [] data = new byte[20]; |
|
|
|
|
|
int max = Math.min(text.length, GattConstants.WRITABLE_CHARACTERISTIC_MAX_LENGTH); |
|
|
|
|
|
for (int i = 0; i < max; i++) { |
|
|
|
|
|
data[i] = text[i]; |
|
|
|
|
|
} |
|
|
|
|
|
Log.d(TAG, "envoi de: " + data.toString()); |
|
|
|
|
|
mBluetoothLeService.writeCharacterisitic(mWritableValueCharac, data); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void requestWritableValue() { |
|
|
private void requestWritableValue() { |
|
|
BluetoothGattService privateService = mBluetoothLeService.getPrivateService(); |
|
|
BluetoothGattService privateService = mBluetoothLeService.getPrivateService(); |
|
|
if (privateService == null) { |
|
|
if (privateService == null) { |
|
|
|