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 hand.dangelo
36 minutes ago
Last post by deckow.madie
36 minutes ago
Last post by ibraun
56 minutes ago
Last post by rosalinda.boyle
2 hours ago
Last post by adrien.bailey
3 hours ago
Last post by mberge
2 hours ago
Last post by harber.eloy
3 hours ago