Java 通过蓝牙接收的消息在android应用程序中被拆分
我正在开发一个Android应用程序,它通过Android设备和一个微控制器(Raspberry Pi)之间的蓝牙通信来实现,我正在使用它来实现这一点。 我可以正常发送数据,没有任何问题,但是,当我尝试从微控制器接收数据时,字符串被拆分为2, 示例:当我从raspberry Pi发送“Hello world!”时,我应该得到: 你好,世界 但我得到: H 埃洛世界Java 通过蓝牙接收的消息在android应用程序中被拆分,java,android,bluetooth,Java,Android,Bluetooth,我正在开发一个Android应用程序,它通过Android设备和一个微控制器(Raspberry Pi)之间的蓝牙通信来实现,我正在使用它来实现这一点。 我可以正常发送数据,没有任何问题,但是,当我尝试从微控制器接收数据时,字符串被拆分为2, 示例:当我从raspberry Pi发送“Hello world!”时,我应该得到: 你好,世界 但我得到: H 埃洛世界 我以前使用过这个库,它工作正常,唯一的区别是我使用的是linux机器而不是windows。此外,该库的开发人员处于非活动状态,因此我
我以前使用过这个库,它工作正常,唯一的区别是我使用的是linux机器而不是windows。此外,该库的开发人员处于非活动状态,因此我无法询问他您好,您可以通过Rfcomm或Gatt接口连接到蓝牙设备,而无需使用任何第三方库 当数据大小较大时,首选Rfcomm。当设备之间的距离较远时,首选蓝牙Gatt
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.ahmedabdelmeged.bluetoothmc.BluetoothMC;
import com.ahmedabdelmeged.bluetoothmc.ui.BluetoothDevices;
import com.ahmedabdelmeged.bluetoothmc.util.BluetoothStates;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class MainActivity extends AppCompatActivity {
public BluetoothMC mBluetoothmc = new BluetoothMC();
private final HomeFragment mHomeFragment = new HomeFragment();
private final MapFragment mMapFragment = new MapFragment();
private final LogFragment mLogFragment = new LogFragment();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView BottomNav = findViewById(R.id.bottom_navigation);
BottomNav.setOnNavigationItemSelectedListener(navListener);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
mHomeFragment).commit();
mBluetoothmc.setOnDataReceivedListener(new BluetoothMC.onDataReceivedListener() {
@Override
public void onDataReceived(String data) {
log.e("Main", data);
}
});
}