Course Content

If you are facing any issue in playing video please use Firefox browser.

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 The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • 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