Friday, 23 August 2013

a simple bluetooth activating application not working on device [on hold]

a simple bluetooth activating application not working on device [on hold] References I made a simple application that simply activates bluetooth on the device by a button click.But as soon as i run it on my device and emulator, my application stops working. Here is the code of that application The java part- package com.aditya.dev.bluetooth_game; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.content.Intent; public class Activity1 extends Activity { protected static final int REQUEST_ENABLE_BT = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout1); requestWindowFeature(Window.FEATURE_NO_TITLE); Button cont= (Button)findViewById(R.id.cont); final BluetoothAdapter mBAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBAdapter == null) { CharSequence text = \"Device doesnt support Bluetooth\"; Toast.makeText(getBaseContext(), text, Toast.LENGTH_SHORT).show(); } cont.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub if(!mBAdapter.isEnabled()){ Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } } }); } } and the XML part-

No comments:

Post a Comment