-
-
Save prime31/0908e6100d7e228f1add to your computer and use it in GitHub Desktop.
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> |
Where can the source for Prime31UnityActivity.jar be found?
The default Unity source can be found at The source for which is in Program Files\Unity-5.1.2\Editor\Data\PlaybackEngines\androidplayer\com\unity3d\player
.
In my case I'd like to customize the UnityPlayerActivity
to get more access to UnityPlayer.
UnityPlayer has a protected method restartFMODAudioDevice
that I'd like to try invoking to see if I can stop the audio playback on pause.
That's to work around an issue with Unity 5.1.2 where audio plays after onPause because the Unity pause event is timing out. It doesn't crash, it just takes a few seconds before the audio stops after hitting the HOME button.
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
thank you!