마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

토글버튼을 이용한 블루투스 on/off [closed]

–3 추천
public  class MainActivity extends Activity  {
			  
				
        private static final int REQUEST_ENABLE_BT = 0;
		private static final BluetoothAdapter mBluetoothAdapter = null;



		public void onCreate(Bundle savedInstanceState) 
			{
				
				super.onCreate(savedInstanceState);
				
				setContentView(R.layout.activity_main);
				//ImageButton bluetooth=(ImageButton) findViewById(R.id.bluetoothbtn);
				//bluetooth.setOnClickListener((OnClickListener) this);
				
				//if(btService ==null){
					//btService=new Bluetooth(this,mHandler);
				//}
				//bluetooth.setSelected(true);
				final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
				final boolean hasBluetooth = (mBluetoothAdapter == null);
				final ToggleButton bluetooth = (ToggleButton) findViewById(R.id.bluetoothbtn);
				final ToggleButton earphone=(ToggleButton) findViewById(R.id.earphonnbtn);
				final ToggleButton phonemic=(ToggleButton) findViewById(R.id.phonemic);
				bluetooth.setOnClickListener(new OnClickListener()
				{
				  public void onClick(View v)
				  {
				    // Perform action on clicks
				    if (bluetooth.isChecked())
				    {
				      if (hasBluetooth && !mBluetoothAdapter.isEnabled())
				      {
				        // prompt the user to turn BlueTooth on
				        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
				        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
				      }
				    }
				    else
				    {
				      if (hasBluetooth && mBluetoothAdapter.isEnabled())
				      {
				        
				        boolean isDisabling = mBluetoothAdapter.disable();
				        if (!isDisabling)
				        {
				          
				        }
				      }
				    }
				  }
				});
				
				
			   
		   	}
		    
        protected void onActivityResult (int requestCode, int resultCode, Intent data)
        {
          if ((requestCode == REQUEST_ENABLE_BT) && (resultCode == RESULT_OK))
          {
			boolean isEnabling = mBluetoothAdapter.enable();
            if (!isEnabling)
            {
              // an immediate error occurred - perhaps the bluetooth is already on?
            }
            else if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_TURNING_ON)
            {
             
            }
          }
        }

 

질문을 종료한 이유: 형식에 맞지않게 올렸습니다.
삐삐빠뿌 (710 포인트) 님이 2015년 8월 13일 질문
삐삐빠뿌님이 2015년 8월 13일 closed
대체 뭐가 문제라는 거죠?
소스만 달랑 적어 놓으면.....
뭐가 문제인지 답을 할 방법이 없잖아요..
...