Skip to content

Android setup

Will McMahan edited this page Mar 18, 2018 · 1 revision

Update your app's build.gradle with the react-native-calendar-events dependency:

dependencies {
  compile project(':react-native-calendar-events')
  ...
}

Update your app's settings.gradle with the following code:

include ':react-native-calendar-events'
project(':react-native-calendar-events').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-calendar-events/android')

Import the CalendarEventsPackage in your app's MainApplication.java and include instance in the array returned by getPackages:

import com.calendarevents.CalendarEventsPackage;

...

  @Override
	protected List<ReactPackage> getPackages() {
		return Arrays.<ReactPackage>asList(
						new MainReactPackage(),
						new CalendarEventsPackage() // <-- Add this line
		);
	}
	...
}

If your app is targeting SDKs 23 or higher, you will be required to request permission to access the calendar. You will need to include the onRequestPermissionsResult method to your app's MainActivity.java, like this:

import com.calendarevents.CalendarEventsPackage;

public class MainActivity extends ReactActivity {
  ...

  @Override
  public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
      CalendarEventsPackage.onRequestPermissionsResult(requestCode, permissions, grantResults);
      super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  }

  ...
}
Clone this wiki locally