Exposing custom Android modules

Often you will find yourself writing React Native applications for both iOS and Android. We have discussed how to go about creating native modules in iOS in the first recipe of this chapter. Now it's time to put our green Android robot hats on and write some Java!

This recipe will take us through writing our first Android native module. We will mimic the functionality of the Exposing custom iOS modules recipe, but for Android. We're going to create a HelloManager native module with a greetUser method that takes a name and isAdmin Boolean value arguments. It will return a greeting message that we will display.

Getting ready

For this recipe, we created a React Native application titled NativeModule.

In this recipe, we ...

Get React Native Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.