Skip to content

Designed for unity developers to call native android interfaces.

Notifications You must be signed in to change notification settings

OddCommon/AndroidHelper

 
 

Repository files navigation

Android Helper

This project incorporates most of our Android repositories into one single package, and categorizes all interfaces into 6 classes: DeviceHelper, StorageHelper, BlueToothHelper, WifiHelper, PowerManagerHelper, AudioHelper.

Prerequirement

Knowledge of Unity Scripting API: AndroidJavaObject

Usage

  1. Clone this repo and make project in Android Studio, or download aar file in release page.

  2. Put AndroidHelper_Vx.x.x.aar into your Unity project's Assets/Plugins/Android directory;

  3. Refer to the sample code below to call the interface.

    //Initialize an AndroidJavaObject with the class name of the interface, 
    //e.g., DeviceHelper, StorageHelper, BlueToothHelper, WifiHelper, PowerManagerHelper.
    AndroidJavaObject  deviceHelper= new AndroidJavaObject("com.picovr.androidhelper.DeviceHelper");
    //Get current activity
    AndroidJavaObject  activityContext = new AndroidJavaClass("com.unity3d.player.UnityPlayer")
    .GetStatic<AndroidJavaObject>("currentActivity");
    //Must call "init" method before call other interface.
    deviceHelper.Call("init", activityContext );
    //Call the interface.
    string puiVersion = deviceHelper.Call<string>("getPUIVersion");

System Signature

The interface marked with star "(*)" requires the system signature.

Refer to the following steps to sign you APK using Pico system signature:

  1. Add sharedUserId in AndroidManifest.xml in Assets/Plugins/Android(If you are using Unity 2019.3.x and above,this directory should be [Unity_PATH]\Editor\Data\PlaybackEngines\AndroidPlayer\Apk\LauncherManifest.xml).

    <manifest ... android:sharedUserId="android.uid.system">
    ...
    </manifest>
  2. Refer to online instruction to sign your apk with system signature.

Resolve Android support library conflict

The installApp API use AndroidX support library which may cause conflict if there is another support libraty in your unity project. To resolve this problem, use "AndroidHelper_vx.x.x_nxs.aar" (no androidx support) in release page. This AAR removed the androidx support library and related reference. Note that the installApp API won't work anymore after doing this.

Interfaces

Note: The interface marked with star "(*)" requires the APK has the system signature

DeviceHelper

StorageHelper

BlueToothHelper

WifiHelper

PowerManagerHelper

AudioHelper

About

Designed for unity developers to call native android interfaces.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 98.5%
  • AIDL 1.5%