我没有很多为Unity3d创建Java(.aar)插件的经验,但我正试图从这样一个插件中设置谷歌认证与Firebase。举个例子来说明我的问题,我首先打开一个unity android应用程序,然后我运行下面的c#代码,在我的显示器上得到一个弹出窗口,让我用google登录。然后我选择了正确的google账户,然后google意图/活动消失了,然后我没有收到 "onActivityResult "被调用的指示。没有错误发生,我无法对我选择的谷歌账户信息进行任何操作。
In the image below, I click submit -> it opens the google sign-in activity in the next picture -> then it returns back to the submit screen (closing the google sign-in activity).
I think my issue is in this line:
activity.startActivityForResult(signInIntent, RC_SIGN_IN);
在这种情况下,"活动 "是由下面的c#unity代码发送的UnityPlayerActivity。我认为这使得我的代码在C# unity代码中寻找一个 "onActivityResult "方法,而不是在java代码中寻找。如果有任何帮助,我将不胜感激。如果你需要任何其他信息或屏幕截图,请告诉我。如果我是个白痴,请叫我出来。
Here is my code for calling the Google Signin Plugin From C# & Unity3d:
AndroidJNIHelper.debug = true;
using (AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
activity_context = activityClass.GetStatic<AndroidJavaObject>("currentActivity");
using (AndroidJavaClass pluginClass = new AndroidJavaClass("com.package.class")) {
if (pluginClass != null) {
GoogleSignInActivity = pluginClass.CallStatic<AndroidJavaObject>("instance");
GoogleSignInActivity.Call("SetContext", activity_context);
GoogleSignInActivity.Call("StartGoogleLogin", activity_context);
activity_context.Call("runOnUiThread", new AndroidJavaRunnable(() => {
GoogleSignInActivity.Call("ShowMessage", "You signed in as " + display_name);
下面是创建Google SignIn活动的代码。
public void StartGoogleLogin(UnityPlayerActivity activity) {
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("some url")
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(activity, gso);
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
activity.startActivityForResult(signInIntent, RC_SIGN_IN);
Log.d(TAG, "Activity Started; Waiting For Result");
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "Result Received!");
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful
GoogleSignInAccount account = task.getResult(ApiException.class);
someMethod(account);
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.d(TAG, "Google sign in failed", e);
setResult(RESULT_OK);
谢谢你的时间。