• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Bluetooth AlertDiaglog Question

justpat

Lurker
Hi all,

I am new to Android and Java. Sorry to ask a stupid question. I am planning to write a bluetooth connection to control a robot. But there are no default bluetooth adapter in the Android emulator. Therefore, I write an alertDialog to remind that there is no default bluetooth adapter. But the alertDialog does not show. How to make it show?

Code:
public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Set up the window layout
		setContentView(R.layout.setbluetooth);
 
        if(D) Toast.makeText(this, "+++ ON CREATE +++", Toast.LENGTH_SHORT).show();
 
		BlueTAdapter = BluetoothAdapter.getDefaultAdapter();
 
        if (BlueTAdapter == null) {
            Log.e(TAG, "It does not have a default bluetooth adapter");
			//setResult(SetBluetooth.Result_Fail);
 
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
 
            builder.setTitle("Warning")
                   .setMessage("It does not have a default bluetooth adapter")
                   .setCancelable(false)
                   .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                    	   dialog.dismiss();
                       }
                       }).create();
            builder.show();
 
 
 
            finish();
            return;
            }

Also, how to debug bluetooth code in the Android emulator as there is no default adapter? When I upload to my phone, it also has the application error. So any solution for that? Thanks!
 
Back
Top Bottom