// Must be launched from the game thread (otherwise the classloader cannot locate the unity
 // java classes we require).
 private static void LaunchBridgeIntent(IntPtr bridgedIntent)
 {
     object[] objectArray = new object[2];
     jvalue[] jArgs       = AndroidJNIHelper.CreateJNIArgArray(objectArray);
     try
     {
         using (var bridgeClass = new AndroidJavaClass(BridgeActivityClass))
         {
             using (var currentActivity = AndroidTokenClient.GetActivity())
             {
                 // Unity no longer supports constructing an AndroidJavaObject using an IntPtr,
                 // so I have to manually munge with JNI here.
                 IntPtr methodId = AndroidJNI.GetStaticMethodID(bridgeClass.GetRawClass(),
                                                                LaunchBridgeMethod,
                                                                LaunchBridgeSignature);
                 jArgs[0].l = currentActivity.GetRawObject();
                 jArgs[1].l = bridgedIntent;
                 AndroidJNI.CallStaticVoidMethod(bridgeClass.GetRawClass(), methodId, jArgs);
             }
         }
     }
     catch (Exception e)
     {
         GooglePlayGames.OurUtils.Logger.e("Exception launching bridge intent: " + e.Message);
         GooglePlayGames.OurUtils.Logger.e(e.ToString());
     }
     finally
     {
         AndroidJNIHelper.DeleteJNIArgArray(objectArray, jArgs);
     }
 }
        public PlatformConfiguration CreatePlatformConfiguration(PlayGamesClientConfiguration clientConfig)
        {
            var config = AndroidPlatformConfiguration.Create();

            using (var activity = AndroidTokenClient.GetActivity())
            {
                config.SetActivity(activity.GetRawObject());
                config.SetOptionalIntentHandlerForUI((intent) =>
                {
                    // Capture a global reference to the intent we are to show. This is required
                    // since we are launching the intent from the game thread, and this callback
                    // will return before this happens. If we do not hold onto a durable reference,
                    // the code calling us will clean up the intent before we have a chance to display
                    // it.
                    IntPtr intentRef = AndroidJNI.NewGlobalRef(intent);

                    PlayGamesHelperObject.RunOnGameThread(() =>
                    {
                        try
                        {
                            LaunchBridgeIntent(intentRef);
                        }
                        finally
                        {
                            // Now that we've launched the intent, release the global reference.
                            AndroidJNI.DeleteGlobalRef(intentRef);
                        }
                    });
                });
                if (clientConfig.IsHidingPopups)
                {
                    config.SetOptionalViewForPopups(AndroidTokenClient.CreateInvisibleView().GetRawObject());
                }
            }
            return(config);
        }