Bluetooth Connection

Has anyone gotten the tutorial Bluetooth connection to work? I have not been able to get it to work. It works with the sample app. What I am trying to do is put this sensor into another app and it would be easier to directly connect to the sensor instead of scanning. Does anyone know how to fix the problem? I am using android studio.

Comments

  • Which bluetooth tutorial are you referring to?

  • https://mbientlab.com/tutorials/Java.html
    That one where it talks about connecting it for the free fall app.

  • Did you follow the tutorial? What fails? Can you post screenshots?
    It's difficult to help without ANY INFORMATION AT ALL TO GO ON here.


  • Thats the first part of the code. When it gets to the retrieveBoard method it does not connect. I am seeing the device on the metwear app on another phone. (Not connected) It just doesn't connect. What do you think the issue is?



  • This is some more information. Where i call the retrieveBoard method and log

  • edited February 2019

    Taking bad snapshots of code will do you no good here. Do you have debug logs? btmon logs? Failures from the IDE/compiler/debugger?
    Sending us snapshots of random code is about as useful as sending my grandma to help you...

    If you do not provide adequate failures logs, reproducible steps, and information, I will close this thread.

  • 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 com.mbientlab.metawear.MetaWearBoard;
    import com.mbientlab.metawear.android.BtleService;

    import bolts.Continuation;

    public class MainActivity extends AppCompatActivity implements ServiceConnection {

    private BtleService.LocalBinder serviceBinder;
    private final String MW_MAC_ADDRESS= "DB:01:94:87:5C:82";
    private MetaWearBoard board;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        // Bind the service when the activity is created
        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 service) {
    
        // Typecast the binder to the service's LocalBinder class
        serviceBinder = (BtleService.LocalBinder) service;
    
        // Create a MetaWear board object for the Bluetooth Device// 
        retrieveBoard();
    }
    
    private void onConnect(BluetoothDevice remoteDevice){
    
        board.connectAsync().continueWith((Continuation<Void, Void>) task -> {
            if (remoteDevice.getName() != null){
                Log.i("Connected", remoteDevice.getName());
            }
            else{
                Log.i("Connected", "Not connected");
            }
            return null;
        });
    }
    
    @Override
    public void onServiceDisconnected(ComponentName name) {
    
    }
    
    public void retrieveBoard() {
    
        final BluetoothManager btManager=
                (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
        final BluetoothDevice remoteDevice=
                btManager.getAdapter().getRemoteDevice(MW_MAC_ADDRESS);
    
    
        board= serviceBinder.getMetaWearBoard(remoteDevice);
        onConnect(remoteDevice);
    }
    

    }

    Theres my code. I am not getting any errors. It won't connect to my sensor. the mac address is correct.

    Here is my run console.

    02/26 20:16:55: Launching app
    $ adb install-multiple -r -t -p com.ist440.btletest /Users/christophervalko/Desktop/btleTest/app/build/intermediates/split-apk/debug/slices/slice_2.apk
    Split APKs installed in 887 ms
    $ adb shell am start -n "com.ist440.btletest/com.ist440.btletest.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
    Client not ready yet..Waiting for process to come online
    Connected to process 14806 on device google-pixel_2-HT78N1A00454
    Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
    W/ist440.btletes: JIT profile information will not be recorded: profile file does not exits.
    I/chatty: uid=10153(com.ist440.btletest) identical 10 lines
    W/ist440.btletes: JIT profile information will not be recorded: profile file does not exits.
    I/InstantRun: starting instant run server: is main process
    D/libEGL: loaded /vendor/lib64/egl/libEGL_adreno.so
    E/libc: Access denied finding property "vendor.debug.egl.profiler"
    W/com.ist440.btletest: type=1400 audit(0.0:87): avc: denied { read } for comm=45474C20496E6974 name="u:object_r:vendor_default_prop:s0" dev="tmpfs" ino=18246 scontext=u:r:untrusted_app:s0:c153,c256,c512,c768 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0
    D/libEGL: loaded /vendor/lib64/egl/libGLESv1_CM_adreno.so
    D/libEGL: loaded /vendor/lib64/egl/libGLESv2_adreno.so
    W/ist440.btletes: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
    W/ist440.btletes: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
    D/OpenGLRenderer: Skia GL Pipeline
    I/Adreno: QUALCOMM build : 6fb5a5b, Ife855c4895
    Build Date : 08/21/18
    OpenGL ES Shader Compiler Version: EV031.25.00.00
    Local Branch : Googledrop_0815
    Remote Branch :
    Remote Branch :
    Reconstruct Branch :
    Build Config : S L 4.0.10 AArch64
    I/Adreno: PFP: 0x005ff110, ME: 0x005ff066
    I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 1
    android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
    I/OpenGLRenderer: Initialized EGL, version 1.4
    D/OpenGLRenderer: Swap behavior 1
    D/BluetoothGatt: connect() - device: DB:01:94:87:5C:82, auto: false
    registerApp()
    D/BluetoothGatt: registerApp() - UUID=2f965ea2-bb69-48d2-bb10-b3f7d9a0e3c6
    D/BluetoothGatt: onClientRegistered() - status=0 clientIf=7
    W/ist440.btletes: Accessing hidden method Landroid/bluetooth/BluetoothGatt;->refresh()Z (light greylist, reflection)
    D/BluetoothGatt: refresh() - device: DB:01:94:87:5C:82
    D/BluetoothGatt: close()
    unregisterApp() - mClientIf=7
    I/Connected: Not connected

  • I figured it out!!!!!!!!!!! I had to also declare blue tooth in manifest.


    This line.

Sign In or Register to comment.