Creates a react native project with Google's Nearby Messaging API already set up and integrated
Learn more about Google's Nearby Messaging API
- Clone repo
git clone https://github.com/carillem/NearbyMessaging.git
cd nearbymessaging_reactnative
yarn reverse
oradb reverse tcp:8081 tcp:8081
yarn
ornpm install
yarn start
ornpm start
- MetroBundler will start up on a tab on your default browser
- Open Android Studio and import
rootFolder/android/
- Update to Gradle version as suggested
- Start and run on Android device
Coming soon.
Note: Only works if your project is fully ejected as a React Native project from expo
A. If you don't have a project yet, clone my TypeScriptExpoTemplate repo using
git clone https://github.com/carillem/TypescriptExpoTemplate
expo eject
What should your app appear as on a user’s home screen? NearbyMessaging
What should your Android Studio and XCode projects be called? NearbyMessaging
-
Uninstall the following packages:
yarn remove <package_name>
ornpm un <package_name>
@types/expo
babel-preset-expo
-
Install metro-react-native-babel-preset library for Metro Bundler:
yarn add metro-react-native-babel-preset
ornpm install metro-react-native-babel-preset
-
Delete
.expo/
library -
Update
babel.config.js
to:module.exports = function(api) { api.cache(true); return { presets: ['module:metro-react-native-babel-preset']; }; };
-
Open Android Studio
-
Import the
root_project/android
folder and sync Gradle(Note: Allow Gradle to be updated to the latest version)
-
Add minSdk to the project level
build.gradle
:build.gradle(Project:<projectName>)
- minSdkVersion = 21
-
Run on android device or emulator
- In the root folder of your project
-
Install the
react-native-nearby-messaging-library-with-notifications
package:yarn add react-native-nearby-messaging-library-with-notifications
ornpm install -i react-native-nearby-messaging-library-with-notifications
(Note: This library is a react native wrapper for the newest version Google’s Nearby Messaging API)
-
Link the library with your react native project with:
react-native link react-native-nearby-messaging-library-with-notifications
- In
root_project/android
via Android Studio
-
Check that
react-native link
installed properly-
In
settings.gradle
rootProject.name = 'NearbyMessaging' include ':react-native-nearby-messaging-library-with-notifications' project(':react-native-nearby-messaging-library-with-notifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-nearby-messaging-library-with-notifications/android') include ':app'
-
In
build.gradle (Module:app)
, add to the list of dependenciesimplementation project(':react-native-nearby-messaging-library-with-notifications')
-
In app > java > com.projectname > MainApplication,
new RNNearbyMessagingLibraryPackage()
should be inside thegetPackages()
functionpublic class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new RNNearbyMessagingLibraryPackage() ); } @Override protected String getJSMainModuleName() { return "index"; } }; @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; } @Override public void onCreate() { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); } }
-
-
Update
app/manifests/AndroidManifest.xml
- Permission requests
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="android.permission.WAKE_LOCK" />
- API Key
<meta-data android:name="com.google.android.nearby.messages.API_KEY" android:value="YOURAPIKEYHERE" />
- Run on Android device to make sure it's all up and running
- Permission requests
-
For typescript, create a declaration file (d.ts) inside the root folder (eg.
declarations.d.ts
):declare module 'react-native-nearby-messaging-library-with-notifications’
-
Import package and call library
import RNNearbyMessagingLibrary from ‘react-native-messaging-library-with-notifications RNNearbyMessagingLibrary.checkLibraryConnection()
-
Add changes to the RNNearbyMessagingLibraryModule as needed. :)