小编Luc*_*sRT的帖子

为所有片段保持蓝牙服务运行

我卡住了,找不到在我的应用程序中重新启动或重新连接蓝牙服务的方法。该应用程序有 3 个片段,由 FragmentPagerAdapter 管理的选项卡。在第一个片段中,您可以发现、关联和与 BT 设备通信。在第二张和第三张卡中,必须与设备交互,无法获得连接或保持服务连接。

这是第一个片段:

public class Conexiones extends Fragment implements ServiceConnection, SerialListener {
    public BluetoothAdapter BTAdapter;
    private ListView listView; // detectados
    private ArrayList<String> mDeviceList;
    public Button conectar, actualizar;
    private ArrayAdapter m_DiscoveredPeersAdapter;
    BluetoothDevice bdDevice;
    BluetoothClass dbClass;
    ArrayList<BluetoothDevice> listaBTDevices = null;
    View view;

    public SerialSocket socket;
    public SerialService service;

    public Conexiones(){

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        view = inflater.inflate(R.layout.fragment_conexiones, container, false );
        BTAdapter = BluetoothAdapter.getDefaultAdapter(); …
Run Code Online (Sandbox Code Playgroud)

java android android-fragments android-bluetooth

6
推荐指数
1
解决办法
1264
查看次数