我即将创建一个蓝牙聊天应用程序。我将它安装在我的手机上,启动它时,它会显示一条错误消息,其中包含一个强制关闭按钮。我的启动活动没有显示错误。下面给出:
package com.group6.abc;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity{
private BluetoothAdapter mBluetoothAdapter=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter==null){
Toast.makeText(this, "Bluetooth Is Not Available", Toast.LENGTH_LONG).show();
finish();
return;
}
Button btn_start=(Button) findViewById(R.id.start);
btn_start.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent intent=new Intent(MainActivity.this,FirstActivity.class);
startActivity(intent);
}
});
}
public void onStart(){
super.onStart();
if(!mBluetoothAdapter.isEnabled()){
Intent enableIntent=new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent,3);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我这边有什么错误吗?任何人请帮助我。
谢谢...