Android Camera Plugin project
The AndroidCameraPlugin is Java plugin used for accessing and handling Android camera. It's use is demonstrated in VisageTrackerUnityDemo sample.
Building the project
The files related to Android Camera Plugin project are located in the Samples/Android/AndroidCameraPlugin
sub-folder of the visage|SDK for Android folder.
Prerequisites to building the sample project are :
- Java JDK (version 17 or higher)
- Android Studio 2020.3.1
- Unity 2020+ (recommended version: 2020.3.21f1)
- Android SDK 6.0 (API level 23) or higher
To build the AndroidCameraPlugin, please follow these steps:
- Open AndroidCameraPlugin project (located in Samples/Android) into Android Studio.
- Navigate to folder AndroidCameraPlugin/app/libs and delete existing file classes.jar
- Navigate to directoy where Unity is installed and copy file classes.jar (typically located in C:\Program Files\Unity\Editor\Data\PlaybackEngines?\androidplayer\Variations\mono\Development\Classes)
- Paste the file to AndroidCameraPlugin/app/libs
- Navigate to directoy where Unity is installed and copy directory tree unity3d (typically located in C:\Program Files\Unity\Editor\Data\PlaybackEngines?\androidplayer\Source\com)
- Paste the directory structure to AndroidCameraPlugin\app\src\main\java\com
- Open Gradle on the right and click "Refresh all Gradle projects" under Gradle projects
- Under Gradle projects, go to AndroidCameraPlugin -> Tasks -> other
- Double click on task exportJar and AndroidCameraPlugin.jar will be created in the AndroidCameraPlugin/app/release folder
- AndroidCameraPlugin.jar and AndroidManifest.xml should be replaced with new versions in Plugins/Android folder of your Unity project.
NOTE: Package name in AndroidManifest.xml should match the package name in CameraActivity.jar
Implementation overview
Project is used for handling camera on Android. This is realised as Android activity which is created from C# script in Unity when the application starts. Switching between front and back facing camera is done by calling Android activity's functions from Unity script. VisageTrackerUnityPlugin provides Java interface to events such as sending frames from camera to tracker and camera parameters changes.
AndroidCameraPlugin source code is available here.