5***@qq.com
5***@qq.com
  • 发布:2021-09-24 16:58
  • 更新:2022-06-10 14:48
  • 阅读:790

在开发android module 原生插件的时候我想实现contenxt.bindService(Intent,callback,flag)绑定服务总是返回false,可有大神遇到过这个问题

分类:uni小程序sdk

在开发android module 原生插件的时候我想实现contenxt.bindService(Intent,callback,flag)

private final ServiceConnection mServiceConnection = new ServiceConnection() {

    @Override  
    public void onServiceConnected(ComponentName componentName,  
                                   IBinder service) {  
        mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService();  

        if(sInstance != null)  
            mBluetoothLeService.initialize(sOptions);  
        Log.e("jxsmallview","Service connection successful");  
        if (!mBluetoothLeService.initBLE()) {  
            Log.e("xxxxxxxx", "Unable to initBLE Bluetooth");  
        }  
        // Automatically connects to the device upon successful start-up  
        // initialization.  
    }  

    @Override  
    public void onServiceDisconnected(ComponentName componentName) {  
        Log.e("xxxxxxxx","mBluetoothLeService is null");  
        mBluetoothLeService = null;  
    }  
};  

Intent gattServiceIntent = new Intent(context, BluetoothLeService.class);
context.bindService(gattServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);

context=mWXSDKInstance.getContext();
context=mWXSDKInstance.getContext().getApplicationContext();
context=mWXSDKInstance.getContext().getBaseContext().getApplicationContext();
context=mUniSDKInstance.getContext();
context=mUniSDKInstance.getContext().getApplicationContext();
上面的context全部换了个遍也没成功..................

2021-09-24 16:58 负责人:无 分享
已邀请:
x***@126.com

x***@126.com

将服务注册到主工程里面 context=mWXSDKInstance.getContext(); 可以成功

  • 5***@qq.com

    你这是系统服务可以这样.应为系统服务在启动的时候已经加载了.而自己的服务需要用的时候才加载,加载有个过程.代码执行完可能服务还没加载,这时候在Connected中拿到的回调可能就是空的

    2023-03-03 11:14

xinqianbobo

xinqianbobo

大佬你实现了吗?我也是获取上下文的时候一直是null

该问题目前已经被锁定, 无法添加新回复