Open Bajrang-Sharma opened 1 year ago
Hello,
We don't see any problems from the log, because we haven't used react-native; We have users who use Flutter and search and call it by themselves; You'd better use react native to create a Demo, and then call native to try! Then put the SDK file in it; If there is a problem, you can search more online!
Best regards!
Hello,
We don't see any problems from the log, because we haven't used react-native; We have users who use Flutter and search and call it by themselves; You'd better use react native to create a Demo, and then call native to try! Then put the SDK file in it; If there is a problem, you can search more online!
Best regards!
Thanks for valuable reply
Hi, TestBleLib implementation in React-Native for Android using java interface but we are facing issues to calling MegaBleCallback methods
package com.gtsportal.nativeinterface; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.uimanager.IllegalViewOperationException; import android.util.Log; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter.LeScanCallback; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothManager; import java.io.ByteArrayOutputStream;
import io.mega.megablelib.; import io.mega.megablelib.enums.GLUMode; import io.mega.megablelib.enums.MegaBleBattery; import io.mega.megablelib.model.MegaBleDevice; import io.mega.megablelib.model.bean.; import io.mega.megableparse.MegaPrBean; import io.mega.megableparse.MegaRawData; import io.mega.megableparse.MegaSpoPrBean; import io.mega.megableparse.ParsedHRVBean; import io.mega.megablelib.MegaBleCallback; //import com.gtsportal.MRingController;
import android.Manifest; import android.app.Activity; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import android.content.pm.PackageManager; import android.content.Context; import androidx.core.content.PermissionChecker; //import android.support.v4.app.ActivityCompat; //import android.support.v4.content.ContextCompat; import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMapKeySetIterator; import com.facebook.react.bridge.WritableNativeMap;
import java.util.ArrayList; import java.util.HashMap; import java.util.List;
public class MRingNModule extends ReactContextBaseJavaModule {
private BluetoothAdapter BA;
public static ReactContext m_context = null;
public MegaBleClient client;
MRingNModule.mCallbacks innerObject = new MRingNModule.mCallbacks();
final Activity activity = getCurrentActivity();
//MRingNModule outerObject = new MRingNModule();
//MRingNModule.mCallbacks innerObject = outerObject.new InnerClass();
//public mCallbacks mCalls = new mCallbacks();
public MRingNModule(ReactApplicationContext reactContext) {
super(reactContext); //required by React Native
m_context = reactContext;
Log.d("GTSApp0", "MRingNModule: ");
BA = BluetoothAdapter.getDefaultAdapter();
}
@Override
//getName is required to define the name of the module represented in JavaScript
public String getName() {
return "MRingNModule";
}
@ReactMethod
public void MRingController() {
try {
Log.d("GTSApp", "MRingController: ");
Context context = getReactApplicationContext();
if (BA.isEnabled()) {
Log.d("GTSApp1", "Bluetooth - ON ");
client = new MegaBleBuilder()
.withSecretId("O6kBHUNZXw-2")
.withSecretKey("Bcw3x7ZgRRw77bfzOExNFHhZR8vEOAKb")
.withContext(m_context)
.uploadData(true)
.withCallback(innerObject)
.build();
client.setDebugEnable(true);
} else Log.d("GTSApp", "Bluetooth - OFF ");
} catch (IllegalViewOperationException e) {
Log.d("GTSApp", "MRingNModuleErr: "+e.getMessage());
}
}
static class mCallbacks extends MegaBleCallback {
@Override
public void onConnectionStateChange(boolean connected, MegaBleDevice device) {
super.onConnectionStateChange(connected, device);
Log.d("GTSApp111", "onConnectionStateChange: "+connected);
}
@Override
public void onDeviceInfoReceived(MegaBleDevice device) {
super.onDeviceInfoReceived(device);
Log.d("GTSApp111", "onDeviceInfoReceived: "+device);
}
@Override
public void onError(int code) {
super.onError(code);
Log.d("GTSApp111", "onError-1: ");
//Log.d("GTSApp111", "onError-2: "+code);
}
@Override
public void onBatteryChanged(int value, int status) {
super.onBatteryChanged(value, status);
Log.d("GTSApp111", "onBatteryChanged: "+status);
}
@Override
public void onDfuBleConnectionChange(boolean connected, MegaBleDevice device) {
super.onDfuBleConnectionChange(connected, device);
Log.d("GTSApp111", "onDfuBleConnectionChange: "+connected);
}
@Override
public void onEnsureBindWhenTokenNotMatch() {
super.onEnsureBindWhenTokenNotMatch();
Log.d("GTSApp111", "onEnsureBindWhenTokenNotMatch: ");
}
@Override
public void onHeartBeatReceived(MegaBleHeartBeat heartBeat) {
super.onHeartBeatReceived(heartBeat);
Log.d("GTSApp111", "onHeartBeatReceived: "+heartBeat);
}
@Override
public void onCrashLogReceived(byte[] bytes) {
super.onCrashLogReceived(bytes);
Log.d("GTSApp111", "onCrashLogReceived: "+bytes);
}
@Override
public void onIdle() {
super.onIdle();
Log.d("GTSApp111", "onIdle: ");
}
@Override
public void onKnockDevice() {
super.onKnockDevice();
Log.d("GTSApp111", "onKnockDevice: ");
}
@Override
public void onOperationStatus(int operationType, int status) {
super.onOperationStatus(operationType, status);
Log.d("GTSApp111", "onOperationStatus: "+status);
}
@Override
public void onRawdataCount(int count, int countFromBle, int hr, int spo) {
super.onRawdataCount(count, countFromBle, hr, spo);
Log.d("GTSApp111", "onRawdataCount: "+count);
}
@Override
public void onRawdataParsed(MegaRawData[] data) {
super.onRawdataParsed(data);
Log.d("GTSApp111", "onRawdataParsed: "+data);
}
@Override
public void onRawdataPath(String path) {
super.onRawdataPath(path);
Log.d("GTSApp111", "onRawdataPath: "+path);
}
@Override
public void onRawdataReceived(byte[] data) {
super.onRawdataReceived(data);
Log.d("GTSApp111", "onRawdataReceived: "+data);
}
@Override
public void onReadSn(byte[] a) {
super.onReadSn(a);
Log.d("GTSApp111", "onReadSn: "+a);
}
@Override
public void onReadyToDfu() {
super.onReadyToDfu();
Log.d("GTSApp111", "onReadyToDfu: ");
}
@Override
public void onRssiReceived(int rssi) {
super.onRssiReceived(rssi);
Log.d("GTSApp111", "onRssiReceived: "+rssi);
}
@Override
public void onSetUserInfo() {
super.onSetUserInfo();
Log.d("GTSApp111", "onSetUserInfo: ");
}
@Override
public void onStart() {
super.onStart();
Log.d("GTSApp111", "onStart: ");
}
@Override
public void onSyncDailyDataComplete(byte[] bytes) {
super.onSyncDailyDataComplete(bytes);
Log.d("GTSApp111", "onSyncDailyDataComplete: "+bytes);
}
@Override
public void onSyncingDataProgress(int progress) {
super.onSyncingDataProgress(progress);
Log.d("GTSApp111", "onSyncingDataProgress: "+progress);
}
@Override
public void onSyncMonitorDataComplete(byte[] bytes, int dataStopType, int dataType, String uid, int steps) {
super.onSyncMonitorDataComplete(bytes, dataStopType, dataType, uid, steps);
Log.d("GTSApp111", "onSyncMonitorDataComplete: "+uid);
}
@Override
public void onSyncNoDataOfDaily() {
super.onSyncNoDataOfDaily();
Log.d("GTSApp111", "onSyncNoDataOfDaily: ");
}
@Override
public void onSyncNoDataOfGlu() {
super.onSyncNoDataOfGlu();
Log.d("GTSApp111", "onSyncNoDataOfGlu: ");
}
@Override
public void onSyncNoDataOfHrv() {
super.onSyncNoDataOfHrv();
Log.d("GTSApp111", "onSyncNoDataOfHrv: ");
}
@Override
public void onSyncNoDataOfMonitor() {
super.onSyncNoDataOfMonitor();
Log.d("GTSApp111", "onSyncNoDataOfMonitor: ");
}
@Override
public void onTokenReceived(String token) {
super.onTokenReceived(token);
Log.d("GTSApp111", "onTokenReceived: "+token);
}
@Override
public void onTotalBpDataReceived(byte[] data, int duration) {
super.onTotalBpDataReceived(data, duration);
Log.d("GTSApp111", "onTotalBpDataReceived: "+data);
}
@Override
public void onV2LiveSpoLive(MegaV2LiveSpoLive live) {
super.onV2LiveSpoLive(live);
Log.d("GTSApp111", "onV2LiveSpoLive: "+live);
}
@Override
public void onV2LiveSpoMonitor(MegaV2LiveSpoMonitor live) {
super.onV2LiveSpoMonitor(live);
Log.d("GTSApp111", "onV2LiveSpoMonitor: "+live);
}
@Override
public void onV2LiveSport(MegaV2LiveSport live) {
super.onV2LiveSport(live);
Log.d("GTSApp111", "onV2LiveSport: "+live);
}
@Override
public void onV2ModeReceived(MegaV2Mode mode) {
super.onV2ModeReceived(mode);
Log.d("GTSApp111", "onV2ModeReceived: "+mode);
}
@Override
public void onV2PeriodSettingReceived(MegaV2PeriodSetting setting) {
super.onV2PeriodSettingReceived(setting);
Log.d("GTSApp111", "ononV2PeriodSettingReceivedError: "+setting);
}
@Override
public void onRawdataParsed(int[][] a) {
super.onRawdataParsed(a);
Log.d("GTSApp111", "onRawdataParsed: "+a);
}
}
}
Please suggest/help how can we use Ring-SDK in react-native android using native interface?
Hi macflyang,
Please update, How can we use TestBleLib-SDK in react-native for Android?
Please check my shared implemented code and if you required more details, I will provide you.
Thanks,
How to use “TestBleLib” for Java, Android Native with React-Native?
When trying to use getting below error to implement MegaBleCallback abstract class
Error: invalid method declaration; return type required onConnectionStateChange(Boolean connected, MegaBleDevice device) {
Execution failed for task ':app:compileInternalReleaseJavaWithJavac'.
//MegaBleCallback implementation import io.mega.megablelib.; import io.mega.megablelib.enums.GLUMode; import io.mega.megablelib.enums.MegaBleBattery; import io.mega.megablelib.model.MegaBleDevice; import io.mega.megablelib.model.bean.; import io.mega.megableparse.MegaPrBean; import io.mega.megableparse.MegaRawData; import io.mega.megableparse.MegaSpoPrBean; import io.mega.megableparse.ParsedHRVBean;
public class megaBleCallback extends MegaBleCallback { @override onConnectionStateChange(Boolean connected, MegaBleDevice device) { Log.d("GTS", "onConnectionStateChange: $connected"); if (connected) { megaBleDevice = device; //sendToHandler(device); } else { //handler.sendEmptyMessage(EVENT_DISCONNECTED); } } }
build.gradle file: implementation fileTree(dir: 'libs', include: ['.jar', '.aar']) //using “megablelibopen-1.6.18.aar” sdk implementation "androidx.core:core:1.0.2" implementation "androidx.annotation:annotation:1.1.0" implementation "androidx.appcompat:appcompat:${rootProject.ext.supportLibVersion}" implementation "com.facebook.react:react-native:0.59.10"
Versions: "react": "16.8.3", "react-native": "0.59.10",
Unable to find “MegaBleCallback” import package to extend this abstract class callbacks Please suggest, how can we use in Android native using Java with react-native?