Ok So i have figured out my problem, i now have a new problem in that the value of the seek bar will not change in my Service class as i am swiping and changing its value.
Main Activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView seekBarValue = findViewById(R.id.seekBar2);
seekbar= findViewById(R.id.seekBar1);
seekbar.setMax(20);
// I added intents
Intent serviceIntent = new Intent(this,BleServer.class);
serviceIntent.putExtra("seekbar",seekbar.getProgress());
this.startService(serviceIntent);
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public int progressChangedValue = 0;
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progressChangedValue = progress;
seekBarValue.setText(String.valueOf(progress));
Log.i(TAG, "SeekBar Value: " + progress);
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(MainActivity.this, "Seek bar progress is :" + progressChangedValue,
Toast.LENGTH_SHORT).show();
}
});
Service Activity
// I added onStartCommand
public int onStartCommand(Intent intent, int flags, int startId) {
Integer seekvalue = intent.getIntExtra("seekbar", 0);
Log.i(TAG, "What is the Brightness Value: " + seekvalue );
//Toast.makeText(this,userID, Toast.LENGTH_LONG).show();
return START_STICKY;
}
MainActivity mainActivity = new MainActivity();
public void startServer() {
goForeground1();
Log.d(TAG, "Service: Starting Server");
mGattServer = mBluetoothManager.openGattServer(this, mGattServerCallback);
if (mGattServer == null) {
Log.w(TAG, "Unable to create GATT server");
return;
}
BluetoothGattService service = new BluetoothGattService(SERVICE_UUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
BluetoothGattCharacteristic writeReadCharacteristic = new BluetoothGattCharacteristic(
desiredDimness, BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_WRITE,BluetoothGattCharacteristic.PERMISSION_READ|BluetoothGattCharacteristic.PERMISSION_WRITE);
writeReadCharacteristic.setValue(write);
service.addCharacteristic(writeReadCharacteristic);
mGattServer.addService(service);
}
So now i have a value from onStartCommand, but i am unable to set that value to a characteristic that is outside onStartCommand method, and the value does not change as i change seekbar.