Get started

Before you begin

Before you start to code using the Nearby Connections API:

Request permissions

Before using Nearby Connections, your app must request the appropriate permissions for the Strategy you plan to use. See the section on Strategies and the documentation for Strategy for more information.

For example, in order to use the P2P_STAR Strategy, add the specified permissions to your AndroidManifest.xml:

<!-- Required for Nearby Connections -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Optional: only required for FILE payloads -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Since ACCESS_FINE_LOCATION and READ_EXTERNAL_STORAGE are considered to be dangerous system permissions, in addition to adding them to your manifest, you must request these permissions at runtime, as described in Requesting Permissions.

If the user does not grant all required permissions for the Strategy you plan to use, the Nearby Connections API will refuse to allow your app to start advertising or discovering.