Skip to content

Instantly share code, notes, and snippets.

@prime31
Last active August 22, 2019 15:19
Show Gist options
  • Save prime31/0908e6100d7e228f1add to your computer and use it in GitHub Desktop.
Save prime31/0908e6100d7e228f1add to your computer and use it in GitHub Desktop.
Instructions to make a plugin that needs to override the Unity Activity play nice with others.
In order to take part in the Unity Activity sharing system, there are a few steps you will need to take outlined below. First, some background. You can signify which class you would like to receive all the Activity lifecycle methods. When you implement the methods they should have the exact same signature but they should be *public static void*. That is important! They will not be called if they are not public static void. You can implement 1 or all of the methods. That is entirely up to your needs.
1. Download the Prime31UnityActivity.jar file from here: https://app.box.com/s/xw6hq1ltjaniycc14j21 You are free to distribute the file but *do not change it's name*! That would defeat the purpose of the sharing mechanism!
2. Implement any of the methods that are available in this Gist (https://gist.github.com/prime31/10747997)
3. Perform the AndroidManifest changes below
If successful, on app launch you will see a log that looks like the following:
found Activity proxy class: com.yourpackage.yourclass
Note for plugin vendors: one really simple way to have your plugin "just work" when the Activity sharing system is being used is to perform steps 1 and 2 above and only add the meta-data line to the AndroidManifest. By doing that your plugin will work as it does currently and when the Activity sharing system is being used by the end user.
Manifest Changes:
- add the following line to the AndroidManifest replacing the "com.yourpackage.yourclass" with the full qualified name of the class that you would like to be notified of Activity lifecycle methods.
<meta-data android:name="com.yourpackage.yourclass" android:value="UnityPlayerActivityProxy"/>
- add the following Activity:
<activity android:name="com.prime31.UnityPlayerNativeActivity"
android:label="@string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@Barricks
Copy link

Barricks commented May 17, 2017

Compiler throws an error if you try and use "public static void" as suggested.
If you just use "public void" it compiles but doesn't get called.
What is the answer here?

The answer is to not extend from UnityPlayerNativeActivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment