Android

Quick Start

Download the Latest Version

Run Sample Project

The method to run NaverGame SDK’s sample project in Android studio is as follows.

  1. Using Android Studio, open the project within the sample/navergame-sdk-sample-android-studio folder.

  2. Build the project.

  3. Confirm that the SDK is running normally in the application.

1. App Manifest Settings

Add the access permissions and activity to the AndroidManifest.xml file as is shown in the following.

1.1 NaverGame SDK Access Permission

Add the access permission required for NaverGame SDK.

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

2. Gradle Settings

Set at build.gradle, in measures of modules that will be using the SDK.

2.1 PlugIn Settings

  • NaverGameSdk uses kotlin.

  • Declare the kotlin plugin as shown in the following in the declaration section for plugins.

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

2.2 Library Addition

  • Download the latest library file from https://github.com/naver/navergame-sdk-android/releases

  • Create the libs folder within the project folder and paste the downloaded navergame-sdk-gradle-XXX.aar file.

  • The aar library for Android Studio is the version that manages external libraries to prevent a collision in dependency.

  • The libs folder structure may differ depending on the gradle version and the project settings, but normally its located in the same folder as the src.

2.3 Dependency Settings

  • Add the library used by the NaverGameSdk.

  • Add the library in the Dependency declaration section as shown in the following.

  • Please maintain NaverGameSDK’s version name since the glide library and the retrofit library are not compatible with other versions.

  • In case the glide and the retrofit library conflict with other libraries that are being used, the dependency can be maintained by dividing up the project by libraries.

dependencies {
    implementation file('libs/navergame-sdk-gradle-x.x.x.aar')            // NaverGameSDK
    
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.72"            // Kotlin
    implementation "androidx.viewpager2:viewpager2:1.0.0"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" 
    implementation "com.github.bumptech.glide:glide:3.7.0"                // Glide
    implementation "com.squareup.retrofit2:retrofit:2.6.4"                // Retrofit, Gson
    implementation "com.squareup.retrofit2:converter-gson:2.6.4"          // Retrofit, Gson
}

3. ProGuard Settings

When using the NaverGame SDK, if minifyEnabled is set to true, an option that excludes the ProGuard must be added.

  • Open the proguard-rules.pro file and input the following content.

  • Because ProGuard declarations do not cause problems even if they are duplicated, it can simply be pasted in.

  • The following file can be downloaded from NaverGameSDK Github.

#retrofit 2

# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod

# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations

# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}

# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**

# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit

# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.KotlinExtensions


#end of retrofit2

#gson
##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }



# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

##---------------End: proguard configuration for Gson  ----------
#end of gson

#glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}
#end of glide

#kotlin
-keep class kotlin.** { *; }
-keep class kotlin.Metadata { *; }
-dontwarn kotlin.**
-keepclassmembers class **$WhenMappings {
    <fields>;
}
-keepclassmembers class kotlin.Metadata {
    public <fields>;
    public <methods>;
}
#End of kotlin

#navergame sdk
# Application classes that will be serialized/deserialized over Gson
-keep class com.navercorp.nng.android.sdk.api.service** { *; }
-keep class com.navercorp.nng.android.sdk.api.entity.** { *; }

-keep class com.navercorp.nng.android.sdk.NNGLink** { *; }
-keep class com.navercorp.nng.android.sdk.NNGLink$Companion { *; }
-keepclassmembers class com.navercorp.nng.android.sdk.NNGLink {
    public static ** Companion;
}
-keep class com.navercorp.nng.android.sdk.NNGConfig** { *; }


#end of sdk

4. initialize

initialize the NaverGame SDK such as the following according to the languages supported by NaverGame SDK.

4.1 NaverGame SDK initialization

During the initializing of Navergame SDK, the options have to be set as shown in the following, and the init() method has to be called.

  • ClientId: The Client Id received after registering the application at developers center upon logging in with a Naver Id.

  • ClientSecret: The client secret received after registering the application at developers center upon logging in with a Naver Id.

  • LoungeId: The Lounge Id received after requesting for an official lounge.

public class MainActivity extends Activity {

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /**
     * 네이버 아이디로 로그인 개발자 센터에서 받은 정보로 SDK를 초기화한다.
     * Glink 클래스의 다른 메서드를 호출하기 전에 반드시 초기화를 먼저 해야 한다.
     * 개발자 센터 주소: https://nid.naver.com/devcenter/main.nhn
     */
    final String loungeId = "naver_game_4developer"";
    final String clientId = "197CymaStozo7X5r2qR5";
    final String clientSecret = "evCgKH1kJL";
    NNGLink.initModule(this, loungeId, clientId, clientSecret );
    ...
}

5. Start NaverGame SDK

Run NaverGame SDK after completing the initialization.

5.1 startHome() method

The startHome() method is the method used to start the home banner.

/**
* 홈배너 실
*/
NNGLink.startHome(activity)

Using NaverGameSDK

initModule() method

initialize the NaverGame SDK

public static void initModule
    (Activity activity, String loungeId, String clientId, String secret);

The following case is a demonstration of the implementation of the initModule() method.

final String loungeId = "naver_game_4developer"";
final String clientId = "UKvNABLDsyEJusJGsXL2";
final String clientSecret = "rK4suc_Qd0";
NNGLink.initModule(this, loungeId, clientId, clientSecret );

finishSdk() method

The finishSdk() method is the method that terminates NaverGameSDK. It is called in when the sdk has to be terminated under certain circumstances. For example, the finishSdk() method has to be called to close the sdk when running the in-game menu code that is delivered through the callback of GLinkDelegate.

public static void finishSdk();

startHome() method

Run the home banner.

public static void startHome(Activity activity);

The following case is a demonstration of the implementation of the startHome() method.

   /**
   * 홈 배너 시작
   */
  NNGlink.startHome(activity)

startSorry() method

Exclusively posts a common notification or a notification for maintenance

public static void startSorry(final Activity activity);

The following case demonstrates the implementation of the startSorry() method.

   /**
   * 점검용 배너 시작 
   */
  NNGLink.startSorry(activity)

startBoard(int boardId) method

This is the method that immediately runs the specific bulletin board registered on the Official Lounge Maintenance Page > SDK Maintenance>Bulletin Board Maintenance pages.

public static void startBoard(final Activity activity, int boardId);

The following example is a demonstration of the implementation of the executeBoard() method.

NNGLink.startBoard(activity,1)

startFeed(long feedId, bool isTempFeedId) method

A method that immediately runs with the number of the registered post. Under the case of a scheduled notification post that has been scheduled through scheduled exposure, the number of the scheduled post must be inputted into FeedId and IsTempFeedId must be inputted as True. Before the scheduled post is posted, running the method does not lead to the exposure of the post.

  • FeedId: The number of the notification post or the scheduled notification post.

  • IsTempFeedId: False if the FeedId is a notification post and true if FeedId is a scheduled notification post.

public static void startFeed(final Activity activity, long feedId, boolean isTempFeedId);

The following example is a demonstration of the implementation of the executeFeed() method.

NNGLink.startFeed(activity,50154,false)

writeFeed(int boardId , string title, string content, string imageUri) method

This method runs the writer page. BoardId is the board number, Title is the title of the writing, Text is the content of the writing, and ImageFilePath is the path of the attached image. Only one image may be attached.

Not all parameters are necessary. If entered, they will be set in the writer page in advance.

  • boardId: This is the board number. This can be found in the URL shown while accessing the board through the web, in the form of https://game.naver.com/lounge/{loungeId}/board/{boardId}.

  • title: This is the title of the writing.

  • text: This is the text to be added to the main body.

  • imageFilePath: This is the LocalPath of the image to be attached. In Android, there is a process of obtaining image rights, so if this value is manually entered, it needs to be checked thoroughly.

public static voids writeFeed(final Activity activity, 
int boardId, String text, String context, String imageUri);

The following example is a demonstration of the implementation of the writeFeed() method.

  NNGLink.writeFeed(activity,54,"제목 테스트","본문테스트",
  "content://com.example.contentprovidersample.provider/cheeses")

enableScreenShotDetector(bool enabled) method

This method shows a button for writing by detecting when a user has taken a screenshot. When not summoned, the base value is ON (true).

  • If enabled: true, writing button appears when a screenshot is captured.

public static voids enableScreenShotDetector(boolean enable);

The following example is a demonstration of the implementation of the enableScreenShotDetector() method.

NNGLink.enableScreenShotDetector(true)

putGameId(string gameId) method

This method syncs with NAVER Login and matches the user and their NAVER ID. This can be used to confirm the game ID of users that win event draws through posts and comments.

This called be called at any point after the init function is called.

  • gameId: Input an identifiable game ID. Only one game ID is saved for one NAVER ID.

public static voids putGameId(String gameId);

The following example is a demonstration of the implementation of the putGameId() method.

  NNGLink.putGameId("naver_game_id_for_test")

getCountryCode() method

Obtain the countryCode of the Android device.

public static String getCountryCode(Activity activity);

The countryCode is the country code (ISO 3166-1 alpha-2) composed of two alphabets. This enables branch processing by countries within the codes. The notable country codes are as shown in the following. Refer to the link for other country codes.

Country Code

Country

CN

China

JP

Japan

KR

Republic of Korea

TH

Thailand

US

United States of America

The following is an example of using the getCountryCode() method to reset the SDK exclusively for Korea.

if (NNGLink.getCountryCode(getActivity()).equals("KR")) {
    NNGLink.initModule(getActivity() ,LOUNGE_ID, CLIEND_ID, CLIENT_SECRET);
    NNGLink.startHome(getActivity());
}

NNGCallbackListener Callback Listener

In the case that a specific event occurs within the Sdk, the delivery is made using the callback listener. The registration method is as follows.

NNGLink.setSdkLoadListener(new NNGCallbackListener() {
        @Override
        public void onSdkDidLoaded() {
            nngSdkLoaded();
        }

        @Override
        public void onSdkDidUnloaded() {
            nngSdkUnLoaded();
        }

        @Override
        public void onCallInGameMenuCode(@NotNull String moveTo) {
            nngSdkCallInGameMenuCode(moveTo);
        }
    });

onSdkDidLoaded() method

Occurs when the NaverGameSdk is running.

onSdkDidLoaded() method

Occurs when NaverGameSdk is terminated.

onCallInGameMenuCode() method

Occurs when the in-game menu code has to be run in NaverGameSdk. Used when an 'In-Game Menu’ has been registered on the banners of Official Lounge Maintenance> Page >SDK Maintenance>Banner Maintenance pages. Depending on the Android and iOS platforms, the registered values are delivered independently, so if different values have been inputted, they must be processed independently.

Horizontal Mode, Vertical Mode

Naver Game SDK supports both horizontal and vertical modes. Under Android environments, the horizontal mode and the vertical mode is applied automatically according to the screen’s horizontal and vertical orientation without the need of additional settings.

Last updated