如何在android中打开/关闭蓝牙?

如何在android中打开/关闭蓝牙?,android,bluetooth,Android,Bluetooth,我一直在尝试通过以下代码获取android中蓝牙的状态: 我在onCreate()方法中实例化了BluetoothAdapter,并像这样调用了blue.isEnabled() if(blue.isEnabled()){ .... } 但是我一直收到这个错误..是的,我已经声明了Bluetooth 错误日志 请帮忙!谢谢 完整代码 从BluetoothAdapter.getDefaultAdapter()文档: Returns the default local adapter, or nul

我一直在尝试通过以下代码获取android中蓝牙的状态: 我在
onCreate()
方法中实例化了
BluetoothAdapter
,并像这样调用了
blue.isEnabled()

if(blue.isEnabled()){
....
}
但是我一直收到这个错误..是的,我已经声明了
Bluetooth

错误日志

请帮忙!谢谢

完整代码


BluetoothAdapter.getDefaultAdapter()
文档:

Returns
the default local adapter, or null if Bluetooth is not supported on this hardware platform
您是否在仿真器上检查代码?
或者在没有蓝牙的手机上?

@user1281750好的,我已经更新了代码。是的,在emulator上检查。让我看看蓝牙支持。深沉的声音:没有蓝牙支持。@YuvalGiveon是的,你们是对的。谢谢你的帮助。我有真正的设备。:)
public class main extends Activity implements OnClickListener{

    Button CallButton, SMSButton, BirthdayButton, BusinessButton; 
    BluetoothAdapter b1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_main);
        b1 = BluetoothAdapter.getDefaultAdapter();

        Initialiser();

    }

    private void Initialiser() {

        CallButton = (Button) findViewById(R.id.CallButton);
        SMSButton = (Button) findViewById(R.id.SMSButton);
        BirthdayButton = (Button) findViewById(R.id.BirthdayButton);
        BusinessButton = (Button) findViewById(R.id.BusinessButton);


        CallButton.setOnClickListener(this);
        SMSButton.setOnClickListener(this);
        BirthdayButton.setOnClickListener(this);
        BusinessButton.setOnClickListener(this);


    }


    public void onClick(View arg0) {
    switch(arg0.getId()){
    case R.id.CallButton:
        startActivity(new Intent(this, CallRemind.class));
        break;
    case R.id.SMSButton:
        Toast.makeText(this, "SMS Button", Toast.LENGTH_LONG).show();
        startActivity(new Intent(this, SMSReminder.class));
        break;
    case R.id.BirthdayButton:
        Toast.makeText(this, "Birthday Button", Toast.LENGTH_LONG).show();

        b1.enable();
        break;
    case R.id.BusinessButton:
        Toast.makeText(this, "Business Button", Toast.LENGTH_LONG).show();
        break;
    }


    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.layout_main, menu);
        return true;
    }



}
Returns
the default local adapter, or null if Bluetooth is not supported on this hardware platform