메타 데이터의 끝으로 건너뛰기
메타 데이터의 시작으로 이동

You are viewing an old version of this content. View the current version.

현재와 비교 View Version History

« 이전 버전 4 다음 »


Initialization and Status Change Event Processing


SDK Initialization

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Initialization and Status Change Event Processing SDK Example'.

import com.kakaogame.KGTApplication;
import com.kakaogame.KGTConfig;

/**
 * When using a single app
 */
KGTConfig config = new KGTConfig();
config.setAppInfo(
	"909428", // appID
	"c3c38bbfa3828b342d946e9770c974d0", // appSecret
	"1.0.0", // appVersion
	"googlePlay", // market
	"14", // ageRating
	KGTServerType.QA, // server type
	KGTLogLevel.Error // log level
);

/**
 * When using an app group
 */
Map<String, String> appsForAppGroup = new HashMap<>();
appsForAppGroup.put("909428", "c3c38bbfa3828b342d946e9770c974d0");
appsForAppGroup.put("921478", "5891c32124ca35821890a0bc1cec77a5");

KGTConfig config = new KGTConfig();
config.setAppGroupInfos(
	"tubeAppGroup", // appGroupId
	appsForAppGroup, // app info map
	"1.0.0", // appVersion
	"googlePlay", // market
	"14", // ageRating
	KGTServerType.QA, // server type
	KGTLogLevel.Error // log level
);


KGTApplication.initSDK(this, config);

Start

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Initialization and Status Change Event Processing SDK Example'.

import com.kakaogame.KGTApplication;
import com.kakaogame.KGTIdpProfile;
import com.kakaogame.KGTPlayer;
import com.kakaogame.KGTResult;

KGTApplication.start(activity, null, result -> {
	if (result.isSuccess()) {
		// If the start is successful

		// Check if auto-login is enabled
		boolean isLoggedIn = KGTPlayer.isLoggedIn();

		if (isLoggedIn) {
			// The ID of the current Player issued by the platform
			String playerId = KGTPlayer.getCurrentPlayer().getPlayerId();

			// Platform access token (ZAT)
			String accessToken = KGTPlayer.getCurrentPlayer().getAccessToken();

			// Retrieve the current IDP authentication information
			KGTIdpProfile idpProfile = KGTPlayer.getCurrentPlayer().getIdpProfile();

			// [TODO] Move to the game screen.
		} else {
			// [TODO] If auto-login is not enabled, move to the login screen.
		}
	} else {
		// If the start fails - since initialization failed, you should retry the start or exit the app.
		int resultCode = result.getCode();

		if (resultCode == KGTResult.KGTResultCode.NETWORK_FAILURE 
			|| resultCode == KGTResult.KGTResultCode.SERVER_TIMEOUT
			|| resultCode == KGTResult.KGTResultCode.SERVER_CONNECTION_FAILED) {
			// [TODO] If a network error occurs, inform the user that the start failed due to a network issue and retry.
		} else {
			// [TODO] If another error occurs, provide an error message and prompt to retry the start. - If the problem persists, check the error code and logs to determine the cause.
		}
	}
});

Pause

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Initialization and Status Change Event Processing SDK Example'.

import com.kakaogame.KGTApplication;
import com.kakaogame.KGTResult;
 
KGTApplication.pause(activity, result -> {
	//
});

Resume

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Initialization and Status Change Event Processing SDK Example'.

import com.kakaogame.KGTApplication;
import com.kakaogame.KGTResult;
 
KGTApplication.resume(activity, result -> {
	if (result.isSuccess()) {
		// [TODO] If resume is successful, resume the game screen.
	} else {
		// [TODO] If resume fails, move to the login screen if it's an authentication failure, and otherwise show an error popup and check whether to retry.
		if (result.getCode() == KGTResult.KGTResultCode.AUTH_FAILURE 
			|| result.getCode() == KGTResult.KGTResultCode.IDP_AUTH_FAILURE) {
			// [TODO] In case of authentication failure, move to the start screen and perform the new login flow again.
		} else {
			// [TODO] For other errors, show an error message and retry the resume process. If the issue persists, close the app.
		}
	}
});

Adding a New Intent Receive Setting

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Initialization and Status Change Event Processing SDK Example'.

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
     
    // Update the current activity with the new intent
    this.setIntent(intent);
}

Login


매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Login SDK Example'.

Logging In Without Using the Default Login UI

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Login SDK Example'.

import com.kakaogame.KGTApplication;
import com.kakaogame.KGTIdpProfile;
import com.kakaogame.KGTPlayer;
import com.kakaogame.KGTResult;

// Set the IdpCode for the login
KGTIdpProfile.KGTIdpCode code = KGTIdpCode.Kakao;

// Log in with a specific IDP
KGTPlayer.login(activity, code, result -> {
	if (result.isSuccess()) {
		// IDP login and platform login succeeded

		// The current Player ID issued by the platform
		String playerId = KGTPlayer.getCurrentPlayer().getPlayerId();

		// Platform access token
		String accessToken = KGTPlayer.getAccessToken();

		// Retrieve the current IDP authentication information
		KGTIdpProfile idpProfile = KGTPlayer.getCurrentPlayer().getIdpProfile();

		// [TODO] Since login was successful, proceed to the game screen.
	} else {
		// IDP login or platform login failed
		// [TODO] In case of login failure, inform the user and allow a retry.

		if (result.getCode() == KGTResult.KGTResultCode.NETWORK_FAILURE 
			|| result.getCode() == KGTResult.KGTResultCode.SERVER_TIMEOUT
			|| result.getCode() == KGTResult.KGTResultCode.SERVER_CONNECTION_FAILED) {
			// [TODO] If a network error occurs, prompt the user to retry the login.
		} else if (result.getCode() == KGTResult.KGTResultCode.USER_CANCELED) {
			// [TODO] If the user canceled the login process, keep the login screen active.
		} else if (result.getCode() == KGTResult.KGTResultCode.BLOCKED_BY_POLICY) {
			// [TODO] The login was attempted from a blocked country code or IP range. Handle accordingly.
		} else {
			// [TODO] For any other errors, display an error message and prompt the user to retry login. - Check the error code and logs to identify the cause.
		}
	}
});

Logout


매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Logout SDK Example'.

Logging Out Without Using the Default Logout UI

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Logout SDK Example'.

import com.kakaogame.KGTPlayer;
import com.kakaogame.KGTResult;

// Logout request
KGTPlayer.logout(activity, false, result -> {
	if (result.isSuccess()) {
		// Logout successful

		// [TODO] Return to the start screen
	} else {
		// Logout failed
	}
});

Unregistration


  • 탈퇴 UI를 개발사에서 직접 구현하고 싶을 경우(탈퇴 UI를 사용하고 싶지 않은 경우)를 위해서, 탈퇴 API가 제공됩니다.

Unregistering Without Using the Default Unregistration UI

기본 탈퇴 UI를 사용하지 않는 탈퇴하는 예제입니다.

import com.kakaogame.KGTPlayer;
import com.kakaogame.KGTResult;

// Unregister request
KGTPlayer.unregister(activity, false, result -> {
	if (result.isSuccess()) {
		// Unregistration successful

		// [TODO] Return to the start screen
	} else {
		// Unregistration failed 
	}
});

Account Linking


매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Account Linking SDK Example'.

Linking Accounts Without Using the Default Account Linking UI

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Account Linking SDK Example'.

import com.kakaogame.KGTPlayer;
import com.kakaogame.KGTIdpProfile;
import com.kakaogame.KGTResult;

// Set the IdpCode to log in with
KGTIdpProfile.KGTIdpCode code = KGTIdpCode.Kakao;

// Connect account with a specific idp
KGTPlayer.connect(activity, code, result -> {
	if (result.isSuccess()) {
		// IDP connection successful
		// Player ID will not change.
	} else {
		// IDP connection failed

		if (result.getCode() == KGTResult.KGTResultCode.INVALID_PARAMETER) {
			// Invalid parameter passed
			// e.g., activity is null
		} else if (result.getCode() == KGTResult.KGTResultCode.NOT_AUTHORIZED) {
			// The current state is not authorized
		} else if (result.getCode() == KGTResult.KGTResultCode.INVALID_STATE) {
			// The currently authenticated IDP is not device authentication
		} else if (result.getCode() == KGTResult.KGTResultCode.ALREADY_USED_IDP_ACCOUNT) {
			// The account is already authenticated
		} else {
			// Other errors occurred
		}
	}
});

Profile


Retrieve My Information

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Profile SDK Example'.

import com.kakaogame.KGTPlayer;

KGTPlayer localPlayer = KGTPlayer.getCurrentPlayer();

Retrieve My IDP Information

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Profile SDK Example'.

import com.kakaogame.KGTPlayer;
import com.kakaogame.KGTIdpProfile;

KGTIdpProfile idpProfile = KGTPlayer.getCurrentPlayer().getIdpProfile();

System Information


Retrieve Language Code

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import com.kakaogame.KGTSystem;

String languageCode = KGTSystem.getLanguageCode();

Retrieve Language Tag

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import com.kakaogame.KGTSystem;

String languageCode = KGTSystem.getLanguageTag();

Retrieve Country Code

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import com.kakaogame.KGTSystem;

String countryCode = KGTSystem.getCountryCode();

Retrieve IP-based Country Code

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import com.kakaogame.KGTSystem;

String countryCode = KGTSystem.getGeoCountryCode();

Retrieve Device ID

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import com.kakaogame.KGTSystem;

String deviceId = KGTSystem.getDeviceId();

Retrieve Device Model

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import com.kakaogame.KGTSystem;

String deviceModel = KGTSystem.getDeviceModel();

Retrieve OS Name

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import com.kakaogame.KGTSystem;

String osName = KGTSystem.getOSName();

Retrieve Network Connection Status

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import com.kakaogame.KGTSystem;

boolean networkConnected = KGTSystem.isNetworkConnected();

Retrieve Connected Network Type

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_System Information SDK Example'.

import com.kakaogame.KGTSystem;

String networkType = KGTSystem.getNetworkType();

Kakao Integration Feature


Setting Up KakaoTalk Game Message Reception

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import com.kakaogame.KGTKakaoTalk;

// Display the KakaoTalk game message reception setting view
KGTKakaoTalk.showSetting(activity, result -> {
	if (result.isSuccess()) {
		// Successfully set KakaoTalk game message reception
		boolean allowMessage = result.getContent(); // Whether message reception is allowed
	} else if (result.getCode() == KGTResult.KGTResultCode.NOT_KAKAOTALK_USER) {
		// The logged-in user is not a KakaoTalk user. This occurs if the account is only registered with KakaoStory and not with KakaoTalk.
	} else {
		// Failed to set KakaoTalk game message reception
	}
});

Retrieve KakaoTalk Profile

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import com.kakaogame.KGTKakaoTalk;
import com.kakaogame.KGTKakaoTalkProfile;

// Retrieve KakaoTalk profile
KGTKakaoTalk.talkProfile(result -> {
	if (result.isSuccess()) {
		// Successfully retrieved KakaoTalk profile
		talkProfile = result.getContent(); // The KakaoTalk profile information of the logged-in user
	} else if (result.getCode() == KGTResult.KGTResultCode.NOT_KAKAOTALK_USER) {
		// The logged-in user is not a KakaoTalk user. This occurs if the account is only registered with KakaoStory and not with KakaoTalk.
	} else {
		// Failed to retrieve KakaoTalk profile
	}
});

Retrieve KakaoTalk Game Friend List

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import com.kakaogame.KGTKakaoTalk;
import com.kakaogame.KGTKakaoFriendProfile;

// Retrieve the list of game friends
KGTKakaoTalk.friends(result -> {
	if (result.isSuccess()) {
		// Successfully retrieved the KakaoTalk game friends list.
		List<KGTPlayer> friendList = result.getContent(); // Game friends list
		
		for (KGTPlayer player : friendList) {
            KGTKakaoFriendProfile kakaoProfile = (KGTKakaoFriendProfile)player.getIdpProfile();
        }
	} else if (result.getCode() == KGTResult.KGTResultCode.NOT_KAKAOTALK_USER) {
		// The logged-in user is not a KakaoTalk user. This occurs if the account is only registered with KakaoStory and not with KakaoTalk.
	} else {
		// Failed to retrieve the KakaoTalk game friends list
	}
});

Sending KakaoTalk Game Messages

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import com.kakaogame.KGTKakaoFriendProfile;
import com.kakaogame.KGTKakaoTalk;
import com.kakaogame.KGTKakaoTalkProfile;

// Friend object retrieved through the friends API
KGTKakaoFriendProfile kakaoProfile; // Kakao profile (KGTKakaoFriendProfile object)

// [TODO] Set the Template ID
String templateId = "";

// [TODO] Set the arguments for the message template
Map<String, String> args = new LinkedHashMap<>();
if (talkProfile != null) {
	args.put("${nickname}", talkProfile.getNickname());
}
args.put("rog_link", "test=100&hello=20111");
args.put("bruce2", "test=100&hello=20111");

// Send a KakaoTalk game message
KGTKakaoTalk.sendGameMessage(kakaoProfile, templateId, args, result -> {
	if (result.isSuccess()) {
		// Successfully sent a KakaoTalk chat message
	} else {
		if (result.getCode() == KGTResult.KGTResultCode.MESSAGE_SETTING_DISABLE) {
			// The recipient has set message reception to disabled
		} else if (result.getCode() == KGTResult.KGTResultCode.EXCEED_DAILY_USAGE) {
			// The daily quota for sending messages from a single app has been exceeded (regardless of the recipient)
		} else if (result.getCode() == KGTResult.KGTResultCode.EXCEED_MONTHLY_USAGE) {
			// The monthly quota for sending messages to a specific person from a single app has been exceeded
		} else {
			// Failed to send the KakaoTalk chat message
		}
	}
});

Sending KakaoTalk Friend Invitation Messages

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import com.kakaogame.KGTKakaoTalk;
import com.kakaogame.KGTKakaoTalkProfile;
import com.kakaogame.KGTKakaoUser;

// [TODO] Set whether to display as a popup
boolean isSingle = true;

// [TODO] Set whether to display as a popup
boolean isPopup = true;
  
// [TODO] Set the template Id
String templateId = "";

// [TODO] Set the parameters for the message template
Map<String, String> args = new LinkedHashMap<>();
if (talkProfile != null) {
	args.put("${nickname}", talkProfile.getNickname());
}

KGTKakaoTalk.sendInviteMessage(activity, isSingle, isPopUp, templateId, args, result -> {
	if (result.isSuccess()) {
		// Successfully sent KakaoTalk invite message
		for (KGTKakaoUser kakaoUser : result.getContent()) {
			// Check the list of users who received the invite message
		}
	} else {
		// Failed to send to all users (need to return a common cause)
		if (result.getCode() == KGTResult.KGTResultCode.MESSAGE_SETTING_DISABLE) {
			// The recipient has set message reception to disabled
		} else if (result.getCode() == KGTResult.KGTResultCode.EXCEED_DAILY_USAGE) {
			// Occurs when a user exceeds the daily quota for sending messages from a specific app (regardless of the recipient)
		} else if (result.getCode() == KGTResult.KGTResultCode.EXCEED_MONTHLY_USAGE) {
			// Occurs when a user exceeds the monthly quota for sending messages to a specific person from a specific app
		} else {
			// Failed to send KakaoTalk invite message
		}
	}
});

Adding a KakaoTalk Channel

매크로 처리 오류 'excerpt-include' : No link could be created for 'EN_Kakao Integration Feature SDK Example'.

import com.kakaogame.KGTKakaoTalk;

// [TODO] Set the channel Id
int channelId = 0;

KGTKakaoTalk.addChannel(plusFriendId, result -> {
	if (result.isSuccess()) {
		// Successfully added the channel
	} else if (result.getCode() == KGTResult.KGTResultCode.NOT_KAKAOTALK_USER) {
		// The logged-in user is not a 'KakaoTalk' user. This occurs when the account is only registered with KakaoStory and not KakaoTalk.
	} else {
		// Failed to add the channel
	}
});

Google Games


Show Achievement Screen

매크로 처리 오류 'excerpt-include' : User 'null' does not have permission to view the page 'EN_구글 게임 SDK 예제'.

import com.kakaogame.KGTGoogleGamesAchievements;

// Show Google Games achievement information screen
KGTGoogleGamesAchievements.showAchievement(activity);

Achievement Unlocked

매크로 처리 오류 'excerpt-include' : User 'null' does not have permission to view the page 'EN_구글 게임 SDK 예제'.

import com.kakaogame.KGTGoogleGamesAchievements;

// [TODO] Set achievement ID
String id = "";

// Unlock achievement
KGTGoogleGamesAchievements.unlock(id);

Display Achievement

매크로 처리 오류 'excerpt-include' : User 'null' does not have permission to view the page 'EN_구글 게임 SDK 예제'.

import com.kakaogame.KGTGoogleGamesAchievements;

// [TODO] Set achievement ID
String id = "";

KGTGoogleGamesAchievements.reveal(id);

Increase Achievement Level

매크로 처리 오류 'excerpt-include' : User 'null' does not have permission to view the page 'EN_구글 게임 SDK 예제'.

import com.kakaogame.KGTGoogleGamesAchievements;

// [TODO] Set achievement ID
String id = "";
int numSteps = 0;

KGTGoogleGamesAchievements.setSteps(id, numSteps);

Set Achievement Level

매크로 처리 오류 'excerpt-include' : User 'null' does not have permission to view the page 'EN_구글 게임 SDK 예제'.

import com.kakaogame.KGTGoogleGamesAchievements;

// [TODO] Set achievement ID
String id = "";
int numSteps = 0;

KGTGoogleGamesAchievements.increment(id, numSteps);
  • 레이블 없음

0 댓글

로그인 상태가 아닙니다. 변경하는 경우 익명으로 표기됩니다. 이미 계정이 있다면 로그인을 원하실 수 있습니다.