为什么我用到蓝牙手机上的时候,刚打开这个程序,就会停止工作呢?代码如下,代码格式什么没错。publicclassMainActivityextendsActivity{BluetoothAdaptermBluetoothAdapter=null;@O...
为什么我用到蓝牙手机上的时候,刚打开这个程序,就会停止工作呢?代码如下,代码格式什么没错。
public class MainActivity extends Activity {
BluetoothAdapter mBluetoothAdapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter != null){
if(mBluetoothAdapter.isEnabled()){
Toast.makeText(this, "OK!", Toast.LENGTH_LONG).show();
}else {
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(intent);
Toast.makeText(this, "Now,bluetooth is open!", Toast.LENGTH_LONG).show();
}
}else{
Toast.makeText(this, "Your equipment does not support bluetooth!", Toast.LENGTH_LONG).show();
}
//setBluetooth();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
展开