質問

I am enabling Bluetooth services through an Intent and calling startActivityForResult() method as follows:

public void enableBT(BluetoothAdapter adapter) {
        if (!adapter.isEnabled()) {
            Intent enableBTIntent = new Intent(
                    BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
            startActivityForResult(enableBTIntent, ENABLE_BT_INTENT);
        }
    }

In this code, adapter is BluetoothAdapter object. After this I call onActivityResult() as follows:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == ENABLE_BT_INTENT)
            if(resultCode == Activity.RESULT_OK)
                 button.setText("Done");

But after I enable the Bluetooth, the button.setText("Done"); piece of code is not executed.

Where is the problem ?

Thanks.

役に立ちましたか?

解決

button.setText(resultCode); gives an error because resultCode is an int so its looking for a resource with that id. See the two methods of setText(). You can use

button.setText(String.valueOf(resultCode));

If you want the String value of that int to be displayed. Otherwise please explain better what you want to happen.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top