So I need to send a btDevice defined in one Activity to a Service in the params so I can get it. Here is the code of the service:
public class Servicio extends JobService implements ServiceConnection {
private static BluetoothDevice btDevice;
public TemperaturaFragment temperaturaFragment;
private MetaWearBoard mwBoard;
@Override
public boolean onStartJob(JobParameters params) {
mJobHandler.sendMessage( Message.obtain( mJobHandler, 1, params ) );
params.getExtras(btDevice = getParcelableExtra(EXTRA_BT_DEVICE));
getApplicationContext().bindService(new Intent(this, BtleService.class), (ServiceConnection) this, BIND_AUTO_CREATE);
return true;
}
@Override
public boolean onStopJob(JobParameters params) {
return false;
}
private Handler mJobHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage( Message msg ) {
Toast.makeText( getApplicationContext(),
"JobService task running", Toast.LENGTH_SHORT )
.show();
jobFinished( (JobParameters) msg.obj, false );
return true;
}
} );
And here is the object that I want to send that is defined in the activity:
btDevice= getIntent().getParcelableExtra(EXTRA_BT_DEVICE);
i want to use builder.setExtras(the object here)
and then in the service getExtras(get the object)
but the set extras say it is a BluetoothDevice and needs a bundle. Any idea? Thanks for the help.
I put this and doesn't work, because the data is just read, not sent
Intent serviceIntent = new Intent(Servicio.class.getName())
serviceIntent.putExtra(1, getIntent().getParcelableExtra(EXTRA_BT_DEVICE));
getApplicationContext().startService(serviceIntent);