Enabling bluetooth discoverable from class

Hi i have one problem. When i am using this code in code in main window everything work fine, but when i move that code to my class and put it into the function the code stop application.

Code:
if (mBluetoothAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) { Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120); startActivity(discoverableIntent); Log.i("Bluetooth", "Device is discoverable"); }

The error is in function startActivity(). Someone can tell me how to make it working well.

Show Accepted Answer

Guest Quick Reply (No URL, BBcode or HTML)

Last post by nicolas.moshe
4 hours ago
Last post by oprice
2 hours ago
Help me plz
Started by alessia51
Last post by uhills
1 hour ago
Last post by qmann
1 hour ago
Last post by cwisozk
32 minutes ago
Last post by ines.hodkiewicz
4 hours ago