小编Sak*_*aku的帖子

检查是否使用Android应用程序启用了蓝牙

我想检查使用Android应用程序的设备中是否启用了蓝牙.我使用了.isEnabled方法.但是有一个错误.我发现(通过注释行)错误是在.isEnabled方法中.你能帮我解决这个问题吗?

final BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();

submitButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        String status = "Bluetooth";

        if(bluetooth != null) {
            if (bluetooth.isEnabled()) {
                String mydeviceaddress = bluetooth.getAddress();
                String mydevicename = bluetooth.getName();
                status = ("Address "+ mydeviceaddress + " Name" + mydevicename);
                Toast.makeText(getApplicationContext(), "" + status + "", Toast.LENGTH_LONG).show();
            } else {
                status = ("Bluetooth not enabled");
                Toast.makeText(getApplicationContext(), "" + status + "", Toast.LENGTH_LONG).show();
            }
        } else {
            Toast.makeText(getApplicationContext(), "" + status + "", Toast.LENGTH_LONG).show();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

android bluetooth

4
推荐指数
2
解决办法
8960
查看次数

Android'后退'按钮动作

我可以将默认Android"后退"按钮的操作分配到另一个按钮吗?我的意思是无需编写代码,是否有预定义的"后退"方法?

谢谢!

android

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×2

bluetooth ×1