We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
Dear developer,

    Due to business adjustments, we will no longer support new developer registrations for Nearby Service starting from September 10, 2024. Existing developers who have already activated Nearby Service can continue to use it. We will notify you separately if there are any changes. Thank you for your support!

SamplesNearby ServiceSample Code

Sample Code

Nearby Connection

The Android Studio sample code implements the function of quickly transferring files by scanning the QR code.

Expand

Sample Code

Find It on Gitee

Find It on GitHub

Nearby file sharing

Click here

Click here

Nearby Message

The Android Studio sample code implements the beacon message subscription function.

Expand

Sample Code

Find It on Gitee

Find It on GitHub

Beacon message subscription

Click here

Click here

NOTE
  • Before using the sample code, read the README file in the sample project carefully. Run the sample code only after you complete the following operations:
    1. Sign in to AppGallery Connect, download the agconnect-services.json file of your app, and copy the file to the app directory of the sample project.

    2. Open the build.gradle file in the sample project, and change the value of applicationId to your app package name.

  • If you want your app to run on devices running Android 12 or later and to communicate with Bluetooth devices, configure the Bluetooth-related permissions as follows in the AndroidManifest.xml file:
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. <uses-permission android:name="android.permission.BLUETOOTH"
    2. android:maxSdkVersion="30" />
    3. <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
    4. android:maxSdkVersion="30" />
    5. <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
    6. <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
    7. <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

    BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE, and BLUETOOTH_CONNECT are runtime permissions. Therefore, you need to explicitly request users to grant the permissions in your app.

Search in Samples
Enter a keyword.