电容器插件不会将参数传递给 java
Capacitor plugin doesn't pass arguments to java
我正在使用 this plugin 在 Ionic React/Capacitor 项目中实施 Google Play 游戏服务。
但是,当我调用 GameServices.showLeaderboard("abcdefghijklmnopqr");
时,logcat 显示以下内容:
05-09 07:44:51.544 15437 15524 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 129018517, pluginId: GameServices, methodName: showLeaderboard
05-09 07:44:51.544 15437 15524 V Capacitor: callback: 129018517, pluginId: GameServices, methodName: showLeaderboard, methodData: {}
05-09 07:44:51.545 15437 15502 W GameServices: showLeaderboard called without providing leaderboardId
如您所见,methodData
是空的。
我完全不知道 java(因此我使用 Capacitor),但这是我能找到的唯一一段代码,在 android\src\main\java\GameServices.java
中,在 GitHub链接。
@PluginMethod()
public void showLeaderboard(final PluginCall call) {
final String leaderboardId = call.getString("leaderboardId");
if (leaderboardId == null) {
Log.w(TAG, "showLeaderboard called without providing leaderboardId");
return;
}
Log.d(TAG, "showLeaderboard called with id: " + leaderboardId);
final GoogleSignInAccount lastSignedInAccount = GoogleSignIn.getLastSignedInAccount(getContext());
if (null == lastSignedInAccount) {
Log.w(TAG,
"cannot find last signed in account, either services are disabled or fingerprint doesn't match services account");
call.resolve();
return;
}
Games.getLeaderboardsClient(getContext(), lastSignedInAccount).getLeaderboardIntent(leaderboardId)
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Log.d(TAG, "showLeaderboard:getIntent:success");
saveCall(call);
startActivityForResult(call, task.getResult(), RC_LEADERBOARD_UI);
} else {
Log.e(TAG, "showLeaderboard:getIntent:error");
call.reject("showLeaderboard:getIntent:error");
}
});
}
你能帮我解决这个问题吗?它似乎是唯一可以远程工作的 Google Play Games Capacitor 插件...
编辑 1:
我应该注意,GameServices.signIn();
方法工作得很好。
编辑2:
尝试调用 GameServices.unlockAchievement("abcdef");
也没有用,记录 Achievement ID must not be null or empty
。显然没有需要参数的方法有效。
在浏览了所有插件代码后,我意识到这些方法需要对象作为参数。
这个有效:
GameServices.showLeaderboard({leaderboardId: "abcdefghijklmnopqr"});
我正在使用 this plugin 在 Ionic React/Capacitor 项目中实施 Google Play 游戏服务。
但是,当我调用 GameServices.showLeaderboard("abcdefghijklmnopqr");
时,logcat 显示以下内容:
05-09 07:44:51.544 15437 15524 V Capacitor/Plugin: To native (Capacitor plugin): callbackId: 129018517, pluginId: GameServices, methodName: showLeaderboard
05-09 07:44:51.544 15437 15524 V Capacitor: callback: 129018517, pluginId: GameServices, methodName: showLeaderboard, methodData: {}
05-09 07:44:51.545 15437 15502 W GameServices: showLeaderboard called without providing leaderboardId
如您所见,methodData
是空的。
我完全不知道 java(因此我使用 Capacitor),但这是我能找到的唯一一段代码,在 android\src\main\java\GameServices.java
中,在 GitHub链接。
@PluginMethod()
public void showLeaderboard(final PluginCall call) {
final String leaderboardId = call.getString("leaderboardId");
if (leaderboardId == null) {
Log.w(TAG, "showLeaderboard called without providing leaderboardId");
return;
}
Log.d(TAG, "showLeaderboard called with id: " + leaderboardId);
final GoogleSignInAccount lastSignedInAccount = GoogleSignIn.getLastSignedInAccount(getContext());
if (null == lastSignedInAccount) {
Log.w(TAG,
"cannot find last signed in account, either services are disabled or fingerprint doesn't match services account");
call.resolve();
return;
}
Games.getLeaderboardsClient(getContext(), lastSignedInAccount).getLeaderboardIntent(leaderboardId)
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Log.d(TAG, "showLeaderboard:getIntent:success");
saveCall(call);
startActivityForResult(call, task.getResult(), RC_LEADERBOARD_UI);
} else {
Log.e(TAG, "showLeaderboard:getIntent:error");
call.reject("showLeaderboard:getIntent:error");
}
});
}
你能帮我解决这个问题吗?它似乎是唯一可以远程工作的 Google Play Games Capacitor 插件...
编辑 1:
我应该注意,GameServices.signIn();
方法工作得很好。
编辑2:
尝试调用 GameServices.unlockAchievement("abcdef");
也没有用,记录 Achievement ID must not be null or empty
。显然没有需要参数的方法有效。
在浏览了所有插件代码后,我意识到这些方法需要对象作为参数。
这个有效:
GameServices.showLeaderboard({leaderboardId: "abcdefghijklmnopqr"});