3

I am writing a test app that exercise the Bluetooth on an Android device. I want my test app to be able to make the device discoverable. Simple search lead me to something like this:

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);

The problem with this method is that it will bring the User Permission dialog. See here

How to automate pressing YES or NO on the permission dialog?

joragupra
  • 692
  • 1
  • 12
  • 23
MHesham
  • 41
  • 5
  • Did you declare the permissions in manifest? Just to be sure. I never used bluetooth in my applications – Erick Filho Jan 07 '14 at 01:47
  • I do have all BT permissions `` and `` – MHesham Jan 07 '14 at 01:56
  • What about BLUETOOTH_PRIVILEGED? this allow you to pair bluetooth devices without user interaction. – Erick Filho Jan 07 '14 at 01:57
  • 4
    This is a security feature. You probably won't find a way to bypass it on non-rooted devices. – dm78 Jan 07 '14 at 01:59
  • BLUETOOTH_PRIVILEGED will give you access to non-public APIs. Do you know a non-public API to change device discoverability? There is none in the public APIs as far as I know. – MHesham Jan 07 '14 at 02:03

1 Answers1

1

Well, I have similar experience and here is my suggestion

  1. If this permission dialog is created by your App, then you can simply use Espresso to find "Yes" button with below codes

    onView(allOf(withText("Yes"), withParent(/* The features of the dialog */))).perform(click());
    
  2. If this dialog is not belonged to your App, then you have to use UIAutomator.
    Android Marshmallow: Test permissions with Espresso?

Community
  • 1
  • 1
holy934
  • 57
  • 9