QuickMatch onJoinedRoom出现错误2

时间:2018-07-25 21:06:42

标签: android google-play-games

我正在尝试通过快速匹配进行连接。我启用了所有功能。启用了API,在Google API控制台的Oauth2列表中添加了调试密钥和生产密钥。

启用了Real-Multiplayer并发布了游戏服务。我正在尝试游戏中的一些示例代码,另外还要与用户签名。

我在export default class DiscoverSearchScreen extends Component { ... render() { return ( <View style={styles.container}> <View style={styles.topView}> <View id="searchRect" style={styles.searchBarRect}> <Image style={styles.searchImage} source={require('../assets/images/search_icon.png')} resizeMode={'contain'} /> <TextInput style={styles.seachInput} placeholder={"Search by gym name, address, city…"} allowsFontScaling={true} returnKeyType={ "search" } underlineColorAndroid='transparent' /> </View> <View style={styles.separator} /> </View> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'white' }, topView: { top: 0, width: '100%', height: deviceHeight*0.12, backgroundColor: 'white', marginTop: getStatusBarHeight(), }, separator: { bottom: 0, width: '100%', height: 0.5, position: "absolute", backgroundColor: '#D6D6D6', }, searchBarRect: { position: 'absolute', flexDirection: 'row', bottom: '15%', width: '90%', height: deviceHeight*0.05, backgroundColor: '#F1F1F1', justifyContent: 'center', alignSelf: 'center', borderRadius: 10, }, seachInput: { alignSelf: 'center', height: '50%', width: '85%', textAlign: "left", color: "rgba(2,2,4,1)", fontSize: 15, fontFamily: "Muli-Regular", letterSpacing: 0, paddingLeft: 10, paddingRight: 20, }, searchImage: { alignSelf: 'center', height: '30%', resizeMode: 'contain', paddingLeft: 15, }, }); 中遇到错误2

我正在尝试使用以下身份登录:

onJoinedRoom

它始终处于连接状态

    public void signInSilently() {
    mGoogleSignInClient.silentSignIn().addOnCompleteListener(getActivity(),
            new OnCompleteListener<GoogleSignInAccount>() {
                @Override
                public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
                    if (task.isSuccessful()) {
                        //onConnected(task.getResult());
                        Utils.logDebug("OnlineFragment.startSignInIntent()","onComplete, isSuccessful.");
                        onConnected(task.getResult());
                    } else {
                        startSignInIntent();
                        Utils.logDebug("OnlineFragment.startSignInIntent()","onComplete, NOT isSuccessful.");
                        task.getException().printStackTrace();
                    }
                }
            });
}

连接后,我将开始新的快速匹配:

private void onConnected(GoogleSignInAccount googleSignInAccount){
    mRealTimeMultiplayerClient = Games.getRealTimeMultiplayerClient(getActivity(), googleSignInAccount);

    startQuickGame();
}

然后我在侦听器中收到错误(仅包含侦听器中提到的函数,未调用其他函数)

    private void startQuickGame() {
    if(getActivity() != null){
        // auto-match criteria to invite one random automatch opponent.
        // You can also specify more opponents (up to 3).
        // TODO: Make the first param's value 2
        Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(1, 1, ROLE_ANY);

        // build the room config:
        RoomConfig roomConfig =
                RoomConfig.builder(mRoomUpdateCallback)
                        .setOnMessageReceivedListener(mMessageReceivedHandler)
                        .setRoomStatusUpdateCallback(mRoomStatusCallbackHandler)
                        .setAutoMatchCriteria(autoMatchCriteria)
                        .build();

        // prevent screen from sleeping during handshake
        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        // Save the roomConfig so we can use it if we call leave().
        mJoinedRoomConfig = roomConfig;

        // create room:
        mRealTimeMultiplayerClient.create(mJoinedRoomConfig);
    }
}

0 个答案:

没有答案