Installation and Configuration
This tutorial guides you through the process of integrating the PeripheralsLib library into your Android Studio project. You will learn how to import the library file, configure your build dependencies, and update your application manifest to support Android 12 and higher.
Prerequisites
- An existing Android Studio project.
- The
peripheralslib.jarfile provided with the integration package.
Step 1: Import the Library
- Open your project in Android Studio.
- Navigate to the Project view (not Android view) in the “Project Explorer”.
- Locate your application module (usually named
app). - Expand the module and look for a folder named
libs.- If the folder does not exist, right-click on the
appfolder, select New > Directory, and name itlibs.
- If the folder does not exist, right-click on the
- Copy the
peripheralslib.jarfile and paste it into thelibsdirectory.
Step 2: Configure Gradle Dependencies
To make the library classes available to your code, you must add it as a dependency in your build configuration.
-
Open the
build.gradlefile for your application module (often labeledModule: app). -
Locate the
dependenciesblock. -
Add the following line to include the JAR file:
implementation files('libs/peripheralslib.jar') -
Sync your project with Gradle files.
Step 3: Configure Android Manifest (Android 12+)
Devices running Android 12 (API level 31) or higher require specific permissions to interact with the system services used by PeripheralsLib. You must declare these permissions in your AndroidManifest.xml.
-
Open
app/src/main/AndroidManifest.xml. -
Add the
QUERY_ALL_PACKAGESpermission and the required<queries>block inside the<manifest>tag, but outside the<application>tag.<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.your.package"> <!-- Required for Android 12+ visibility --> <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" /> <queries> <package android:name="com.redsys.t_android.appservice" /> </queries> <application ...> ... </application> </manifest>
The <queries> block ensures your application can detect and communicate with the underlying service (com.redsys.t_android.appservice) on newer Android versions.
Summary
You have successfully imported the library and configured the necessary permissions. Your project is now ready to instantiate the PeripheralsManager.