I am quite new to Java and would appreciate if someone could explain show me
how can I implement startActivityForResult(Intent, int)
and
onActivityResult()
in Bluetooth discoverability stated
here.
What I want to achieve is: on button Enable BTDisco
click
(if(bttn.getId() == R.id.bt_disco
) my program calls
BTDiscoverable()
method:
public void BTDiscoverable() {
Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,
BT_ENABLE_TIME);
startActivityForResult(discoverableIntent, REQUEST_ENABLE_BT);
}
Now, the dialog pops up. If user clicks no, the program should not
continue. If user click yes, Enable BTDisco
button should become
unavailable and another button, lets call it Start
, becomes available. I
wrote onActivityResult
which would make Start
button available but I
doubt it is done right. Snippet here:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data)
{
if (requestCode == REQUEST_ENABLE_BT)
{
if(resultCode == RESULT_OK)
{
((Button) findViewById(R.id.bt_server_start)).setEnabled(true);
BTCountDown = new BTTimer(BT_TIME_BTTIME,BT_TIME_BTTIME);
BTCountDown.start();
}
}
}
startActivityForResult
is called in BTDiscoverable
method but it does
not provide what I wanted. I have followed this but as I am quite
new here, I have no idea how to implement this in such problem as mine.
The onActivityResult
method is implemented class that extends Activity
.
There are no errors while compiling. Long story, short: R.id.bt_server_start
stays disabled as initially programmed.
Could really use some help.