Some Kontakt.io beacons prerequisites have to be met.
-
Add package
$ yarn add react-native-kontaktio
-
In
android/app/src/main/AndroidManifest.xml
do two things:- Inside the
<manifest />
tag add theandroid.permission.ACCESS_FINE_LOCATION
permission - Inside the
<application />
tag register the Proximity<service />
:
You should add the following two lines:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example2022"> <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application android:name=".MainApplication" ... android:theme="@style/AppTheme"> <activity android:name=".MainActivity" ... </intent-filter> </activity> + <service android:name="com.kontakt.sdk.android.ble.service.ProximityService" android:exported="false"/> </application> </manifest>
(
...
denote omitted lines) - Inside the
-
Android Marshmallow
(6.0) or higher: Don't forget to ask the user to grant theandroid.permission.ACCESS_FINE_LOCATION
permission in your application code - see the minimal example in theREADME
).
When installing both, Android and iOS, steps 1 and 2 only have to be run once for both platforms.
-
Install the package
-
yarn
$ yarn add react-native-kontaktio
-
npm
$ npm install --save react-native-kontaktio
-
-
Link module (use
rnpm
for React Native versions before0.27
)react-native link react-native-kontaktio
-
In
android/app/src/main/AndroidManifest.xml
inside<application />
register the Proximity service:<service android:name="com.kontakt.sdk.android.ble.service.ProximityService" android:exported="false"/>
i.e. your
AndroidManifest.xml
should look similar to this (...
denote omitted lines):<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" ... <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" /> + <service android:name="com.kontakt.sdk.android.ble.service.ProximityService" android:exported="false"/> </application>
-
npm install
$ npm install --save react-native-kontaktio
-
In
android/app/src/main/java/.../MainApplication.java
importKontaktPackage
and add it to the List:import com.artirigo.kontaktio.KontaktPackage; ... return Arrays.<ReactPackage>asList( new MainReactPackage(), ... new KontaktPackage() );
-
In
android/settings.gradle
add:include ':react-native-kontaktio' project(':react-native-kontaktio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-kontaktio/android')
-
In
android/app/build.gradle
- Add dependency
dependencies { compile project(':react-native-kontaktio') ... }
- Add exclusion inside
android
, i.e.
android { ... packagingOptions { exclude 'main/AndroidManifest.xml' } }
-
In
android/app/src/main/AndroidManifest.xml
inside<application />
add<service android:name="com.kontakt.sdk.android.ble.service.ProximityService" android:exported="false"/>