App Crashing when trying to retrieve MetaWear MotionR
Hi
I am trying to connect to the board with the tutorial in Android Studio. I followed the tutorial exactly the way it was in the videos on this webpage. https://mbientlab.com/tutorials/Java.html. I am using the FreeFall app tutorial. It seems to crash right when it gets to retrieveBoard method.
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import bolts.Continuation;
import bolts.Task;
import com.mbientlab.metawear.MetaWearBoard;
import com.mbientlab.metawear.android.BtleService;
public class MainActivity extends AppCompatActivity implements ServiceConnection {
private MetaWearBoard board;
private BtleService.LocalBinder localBinder;
private final String MAC_ADDRESS = "CB:42:F6:6E:2C:7A";
BluetoothAdapter bluetoothAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
getApplicationContext().bindService(new Intent(this, BtleService.class),
this, Context.BIND_AUTO_CREATE);
}
@Override
public void onDestroy() {
super.onDestroy();
// Unbind the service when the activity is destroyed
getApplicationContext().unbindService(this);
}
@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
localBinder = (BtleService.LocalBinder) binder;
retrieveBoard();
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
//This is where the app fails. It keeps saying the bluetooth is null*******
public void retrieveBoard() {
final BluetoothManager btManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
final BluetoothDevice remoteDevice =
btManager.getAdapter().getRemoteDevice(MAC_ADDRESS);
// Create a MetaWear board object for the Bluetooth Device
board = localBinder.getMetaWearBoard(remoteDevice);
board.connectAsync().continueWith(new Continuation<Void, Void>() {
@Override
public Void then(Task<Void> task) throws Exception {
if (task.isFaulted()) {
Log.i("freefall", "Failed to connect");
} else {
Log.i("freefall", "Connected");
}
return null;
}
});
}
My manifest does have the service in there. This line.
Also, i do have the repo in the gradle file and i have the implementation dependency in my gradle file too.
I was wondering what to do. I have been stuck on this for about a month. It seems to work perfectly in the tutorial but not on my computer. I have tried 2 phones on a mac and pc. I don't know if there's an update to this tutorial or if i am missing something small.
Thank you for the help
Comments
Are there any differences between that code vs. what you have? Does the GitHub code work as is?
I got the starter app to work. I will be using this for now. Thankyou.
Resolved