1

Bluetooth接続を作成するチェックボックスが1つあります。問題は、Bluetooth パーミッション リクエスト ダイアログ ボックスが表示され、[ ] を選択するNoと、チェックボックスがオンのままになることです。

このアクティビティからリクエストコードを取得し、取得した場合にチェックボックスをオフにするにはどうすればよいRESULT_CANCELEDですか?

CheckBox turnBtOnOff=(CheckBox)findViewById(R.id.checkBox1);
turnBtOnOff.setOnCheckedChangeListener(new OnCheckedChangeListener()
    {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
        {
            if (isChecked)
            {
                if(!mBluetoothAdapter.isEnabled())
                {
                    Intent enableBtIntent=new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                    startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);  
                    //myAddress=mBluetoothAdapter.getAddress();
                    //Toast.makeText(getBaseContext(), myAddress, Toast.LENGTH_SHORT).show();   
                    }
                }
                else
                {
                    if(mBluetoothAdapter.isEnabled())
                    {
                        mBluetoothAdapter.disable();
                    }
                }
            }
        });
4

6 に答える 6

2
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode ==REQUEST_ENABLE_BT) {
        if (resultCode == RESULT_CANCELED) {
            turnBtOnOff.setSelected(false);
        }
    }
}
于 2012-03-27T10:53:29.293 に答える
0
 protected void onActivityResult(int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case REQUEST_ENABLE_BT: {
            if (resultCode == RESULT_CANCELED) {
                ......
            }
            break;
        }

    }
 }   
于 2012-03-27T10:43:43.397 に答える
0

これを試して :

private static int RESULT_OK=111;
private static int  PICK_CONTACT_REQUEST=112;

protected void onActivityResult(int requestCode, int resultCode,
             Intent data) {
         if (requestCode == PICK_CONTACT_REQUEST) {
             if (resultCode == RESULT_OK) {
                 // ....do your code here
                 // 

             }
         }
     }

幸運を

于 2012-03-27T10:44:02.910 に答える
0

アクティビティから結果を取得するには、onActivityResultをオーバーライドする必要があります。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    //if 12345 is the int value you used to start bluetooth activity then
    if(requestCode == 12345){
        if(resultCode == RESULT_OK){
            //do whatever you want
        }
        else{
            //do whatever you want
        }
    }
}
于 2012-03-27T10:44:22.173 に答える
0

onActivityResult()メソッドをオーバーライドします。

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
        //check for the requestcode here and check/uncheck the checkbox 

}
于 2012-03-27T10:46:47.137 に答える