Course Content

Course Content

Description

Bluetooth Discoverable

 

In this video our topic is Making Bluetooth Discoverable.

We will call startActivityForResult() with the "ACTION_REQUEST_DISCOVERABLE" action Intent.

The "DISCOVERABLE_BT_REQUEST_CODE" constant passed to "startActivityForResult()" is a locally defined integer which must be greater than 0 so that the system will pass back to your code in "onActivityResult()" implementation as the "requestCode" parameter.

By default the device will become discoverable for 120 seconds. You can define a different duration by assigning a different integer value to the "EXTRA_DISCOVERABLE_DURATION" Intent extra.

An app can set any integer value between 0 and 3600 for this duration, any value outside of this range will be reverted to 120.

Example :

protected void makeDiscoverable()

{

Intent discoverableIntent=new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,DISCOVERABLE_DURATION);

startActivityForResult(discoverableIntent, DISCOVERABLE_BT_REQUEST_CODE);

}

public void onActivityResult(int requestCode, int resultCode, Intent data)

{

if(requestCode==ENABLE_BT_REQUEST_CODE)

{

//OTHER CODE

}

else if(requestCode==DISCOVERABLE_BT_REQUEST_CODE)

{

if(resultCode==DISCOVERABLE_DURATION)

{

//Toast Text accordingly.

} else

{

//Toast Text accordingly.

}

} }

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
297K+ Downloads
App Download Section Circle 1
4.5 Rating
App Download Section Circle 2
10K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere