PLUG Android Guide

Quick Start

Download latest version

Run sample project

The method for running a sample project for plugin on Android Studio is described below.

  1. Open the project in sample/navercafesdk-sample-android-studio folder on Android Studio.

  2. Build the project.

  3. Check if the plugin is running normally in the application.

1. Application manifest settings

Add access authority and activity to the AndroidManifest.xml file as described below.

1.1 Access authority for PLUG SDK

Add the access authority that is needed for PLUG SDK.

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

1.2 Access authority for video recording

Add the access authority that is needed for using video recording functions.

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <!-- Required items -->
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>           <!-- Optional items -->

2. Initialization

Initialize PLUG SDK according to the language that is being supported, as explained below.

2.1 PLUG SDK initialization (only supports Korean - Naver cafe)

When initializing PLUG SDK that only supports Korean, apply initialization settings as indicated below and call for init() method.

  • ClientId: Client ID received when registering application on the login developer center using Naver ID

  • ClientSecret: Client secret received when registering application on the login developer center using Naver ID

  • cafeId: Cafe ID init() method received by opening a Naver cafe is the method used for initialization on PLUG SDK.

fpublic class MainActivity extends Activity {

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

    /**
     * Initialize the plugin using the information received from the login developer center using Naver ID.
     * Be sure to carry out initialization first before calling for another method in Glink class.
     * Developer center address: https://nid.naver.com/devcenter/main.nhn
     */
    final int cafeId = 28290504;
    final String clientId = "197CymaStozo7X5r2qR5";
    final String clientSecret = "evCgKH1kJL";
    Glink.init(this, clientId, clientSecret, cafeId);
    ...
}

2.2 PLUG SDK initialization (only supports foreign languages - Moot)

When initializing PlUG SDK that only supports foreign languages, apply initialization settings as indicated below and call for initGlobal() method.

  • consumerKey: Consumer key received by opening the community

  • consumerSecretKey: Consumer secret key received by opening the community

  • cummunityNo: Community No. received by opening the community

  • loungeNo: Lounge No. received by opening the lounge

initGlobal() method is used for carrying out initialization on PLUG SDK that supports foreign languages.

public class MainActivity extends Activity {

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

     /**
     * If you apply for partnership using partner mail, you can receive the community ID and consumer key.
     * Be sure to carry out initialization first before calling for another method in Glink class.
     * Partner mail address: dl_plugsupport@navercorp.com
     */
    final String consumerKey = "PLUGTESTKEY";
    final String consumerSecretKey = "PLUGTESTSECRET";
    final int cummunityNo = 1;
    final int loungeNo = 58;

    // Initialization of plugin for the global community You don’t have to call for initGlobal() method when only using a domestic Naver cafe.
    Glink.initGlobal(this, "PLUGTESTKEY", "PLUGTESTSECRET", cummunityNo, loungeNo)
    ;
}

2.3 Initialization of a plugin that supports the global community and a domestic Naver cafe

Use initGlobal() method and init() method for plugin initialization when it supports both the global community and a domestic Naver cafe.

The following is an example of plugin initialization.

public class MainActivity extends Activity {

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

    /**
     * Initialize the plugin using the information received from the login developer center using Naver ID.
     * Be sure to carry out initialization first before calling for another method in Glink class.
     * Developer center address: https://nid.naver.com/devcenter/main.nhn
     */
    final int cafeId = 28290504;
    final String clientId = "197CymaStozo7X5r2qR5";
    final String clientSecret = "evCgKH1kJL";
    
    // Plug initialization for a domestic Naver cafe
    Glink.init(this, clientId, clientSecret, cafeId);

     /**
     * If you apply for partnership using partner mail, you can receive the community ID and consumer key.
     * Be sure to carry out initialization first before calling for another method in Glink class.
     * Partner mail address: dl_plugsupport@navercorp.com
     */
    final int globalCafeId = 1013329;
    final String neoIdConsumerKey = "IHCd_HmSiMcXOMC37xZ8";
    final String defaultChannel = "";

    // Plugin initialization for the global community You don’t have to call for initGlobal() method when only using a domestic Naver cafe.
    Glink.initGlobal(this, neoIdConsumerKey, globalCafeId);
}

3. Start PLUG SDK

Run PLUG SDK after initialization is complete.

3.1 startHome() method

startHome() method is used for starting PLUG SDK while home tab is selected.

/**
* Start with the home tab
*/
Glink.startHome(activity)

Start / Close PLUG

Start or finish Naver PLUG while a certain tab is selected.

startHome() method

Start the PLUG while home tab is selected.

public static void startHome(Activity activity);

The following is an example of the startHome() method.

   /**
   * Start with the home tab
   */
  Glink.startHome(activity)

stop() method

Immediately close the PLUG screen and exit the PLUG.

public static void stop(final Activity activity);

The following is an example of the stop() method.

   /**
   * Close PLUG
   */
  Glink.stop(activity)

Check if the PLUG screen is open.

public static boolean isShowGlink(Activity activity);

The following is an example for the isShowGlink() method.

   /**
   * Check if plug screen is open.
   */
  Glink.isShowGlink(activity)

Basic channel settings

Settings for the basic channel, which is the community for each language on the PLUG, is applied with the language that is set on the device. If you wish to apply settings to the basic channel with a certain language, use the setChannelCode() method.

public static void setChannelCode(String channelCode);

The following is an example for setting a certain language on the basic channel.

Glink.setChannelCode("en");

Horizontal mode, vertical mode

The PLUG supports both horizontal and vertical modes.

In the Android environment, horizontal and vertical modes are automatically applied without having to apply the setting separately.

Adjust transparency

If you adjust transparency using the adjustment slider on the upper left side of the PLUG screen, you can use the game and the cafe at the same time.

You can set the setTransparentable() method to enable the transparency adjustment slider in the Android environment.

public static void setTransparentable(Activity activity, boolean isTransparentable);

If you set "true" for the isTransparentable parameter value, you can use the transparency adjustment slider (default value: true).

The following is an example of using the transparency adjustment slider.

  /**
   * You can set whether or not to use the transparency adjustment slider.
*/
Glink.setTransparentable(activity, true)

Widget

A widget is an element that is automatically displayed on the screen when the fold button is pressed on the PLUG. You can use the PLUG anywhere in the game by using a widget.

Widget display

You can apply the showWidgetWhenUnloadSDK() method setting in order to display the widget when the fold button is pressed on the PLUG.

public static void showWidgetWhenUnloadSdk(Activity activity, boolean show);

If you set true on useWidget parameter value, widget is displayed when plug window is folded (default value: true).

The following is an example of displaying the widget.

  /**
   * You can decide whether or not to display the widget when the PLUG window is folded.
   */
  Glink.showWidgetWhenUnloadSdk(activity, true);

Run widget

Use the startWidget() method for running the widget.

startWidget() method is supported on PLUG 1.7.0 or above.

public static void startWidget(Activity activity);

The following is an example of running the widget.

/**
 * Run the widget.
 */
Glink.startWidget(activity);

Close widget

Use the stopWidget() method to close the widget.

public static void stopWidget(Activity activity)

The following is an example of force closing the widget.

  /**
   * Close widget
   */
  Glink.stopWidget(activity);

Default position settings for the widget

When the widget is first run, it is displayed on the center-left part of the screen. If you wish to set the default position settings when the widget is first run, use the setWidgetStartPosition() method.

However, when the widget is run again after the user has moved the widget, the widget will be displayed in the position where the user last moved it.

The default position setting for widget is supported on PLUG 2.3.0 or above.

public static void setWidgetStartPosition(Activity activity,
 boolean isLeft, int heightPercentage)

The following is an example for setting the widget's default position to 20% from top, on the right side of the screen.

  /**
   * isLeft: If the value is true, it is displayed on the left. If the value is false, it is displayed on the right.
   * heightPercentage: You can designate the vertical position using %.
   */
  Glink.setWidgetStartPosition(activity, false, 20);

Screen capture

You can capture the game screen by pressing the screen capture button on the widget.

Screen capture button

The screen capture function is run by registering the widget screen capture button click listener (OnWidgetScreenshotClickListener) with the setOnWidgetScreenshotClickListener() method.

public static void setOnWidgetScreenshotClickListener(Glink.OnWidgetScreenshotClickListener onWidgetScreenshotClickListener);

The following is an example of running the widget screen capture button click listener.

  /**
   * Settings for the widget screen capture button click listener
   */
  Glink.setOnWidgetScreenshotClickListener(new Glink.OnWidgetScreenshotClickListener() {
      @Override public void onScreenshotClick() {
        // TODO screen capture and run the PLUG (the following is sudo code)
        String uri = screenCapture();
        Glink.startImageWrite(getActivity(), "title", uri);
      }
    });

Screen capture settings

You can use the setUseWidgetScreenShot() method to enable screen capture functionality.

public static void setUseScreenshot(Activity activity, boolean use);

If you set the parameter value as true, the screen capture button is displayed on the widget (default value: true).

The following is an example of using the screen capture function.

/**
* You can decide whether or not to use the screen capture function.
*/
Glink.setUseScreenshot(activity, true

Video recording

If you press the video recording button, you can record the game screen while playing the game.

  • The video recording function is supported on Android 5.0 or above.

Access authority settings

In order to use the video recording function, you should add access authority on the Androidmanifest.xml file as indicated below.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>

Use the video recording function on the widget

If you press the video recording button on the widget, you can record the game screen while playing the game.

Video recording settings

You can use the setUseVideoRecord() method to enable the video recording function.

public static void setUseVideoRecord(Activity activity, boolean use);

If you set the use parameter value as true, the video recording button will be displayed on the widget (default value: true).

The video recording button is not displayed on the widget for devices using Android 5.0 or below, even if you set use parameter value as true.

The following is an example of using the video recording function.

/**
 * You can decide whether or not to use the video recording function.
 */
Glink.setUseVideoRecord(activity, true)

Recording ended listener

Tasks that should be processed after completing video recording are run by registering that the recording is complete for the listener (OnRecordFinishListener) with the setOnRecordFinishListener() method.

public static void setOnRecordFinishListener(OnRecordFinishListener onRecordFinishListener);

The following is an example of using the recording ended listener.

/**
 * Register recording ended listener
 */
Glink.setOnRecordFinishListener(new Glink.OnRecordFinishListener() {
    @Override public void onRecordFinished(String uri) {
      Glink.startVideoWrite(MainActivity.this, -1, "title", "subject", uri);
    }
  });

Use the video recording function on the game

You can run the video recording button from the game developer to record the game screen.

Start / Stop video recording

Use the startRecord() method to start video recording.

/*
Start video recording.
*/

PlugRecordManager.startRecord(Activity activity);

Use the stopRecord() method to stop video recording.

/*
Stop video recording.
*/

PlugRecordManager.stopRecord();

Video recording callback listener

Callback listener that processes event that is occurred from video recording using the button on game developer should be registered for use.

public interface OnRecordManagerListener {
    void onStartRecord();

    void onErrorRecord();

    void onFinishRecord(String uri);
  }

The following is an example of using the video recording listener.

PlugRecordManager.setOnRecordManagerListener(  
    new PlugRecordManager.OnRecordManagerListener() {
      @Override public void onStartRecord() {
        //record started
      }

      @Override public void onErrorRecord() {
        //recording error
      }

      @Override public void onFinishRecord(String uri) {
        //record finished
      }
    });

App scheme processing

When you press the banner image that is displayed on the home screen of the game PLUG, you can go to the App scheme to run game functions.

You can register the banner image for moving to the App scheme from the cafe management menu.

When the touch event has occurred on the banner image that is moving to the App scheme, functions for processing the App scheme are carried out by registering the App scheme listener (OnClickAppSchemeBannerListener) with the setOnClickAppSchemeBannerListener() method.

public static void setOnClickAppSchemeBannerListener( OnClickAppSchemeBannerListener onClickAppSchemeBannerListener);

The following is an example of using the setOnClickAppSchemeBannerListener() method for processing the App scheme.

// App scheme listener settings
 Glink.setOnClickAppSchemeBannerListener(new Glink.OnClickAppSchemeBannerListener() {
   @Override public void onClickAppSchemeBanner(String appScheme) {
     // Deliver the appScheme text string that is set from cafe management to the plug.
     // Run the code for processing each appScheme.
     Toast.makeText(MainActivity.this, appScheme, Toast.LENGTH_LONG).show();
   }
 });

Callback listener

Register the callback listener to process events that have occurred in the PLUG.

PLUG startup listener

OnSdkStartedListener is callback listener that processes events that have occurred when the PLUG starts.

Tasks that should be processed are carried out by registering OnSdkStartedListener with the setOnSdkStartedListener() method.

public static void setOnSdkStartedListener(Glink.OnSdkStartedListener onSdkStartedListener);

The following is an example of using the PLUG startup listener.

   // PLUG startup listener settings
    Glink.setOnSdkStartedListener(new Glink.OnSdkStartedListener() {
      @Override public void onSdkStarted() {
        Toast.makeText(MainActivity.this, "플러그 시작", Toast.LENGTH_LONG).show();
      }
    });

PLUG closing listener

OnSdkStoppedListener is a callback listener that processes events that have occurred when the PLUG is closing.

Tasks that should be processed are carried out by registering OnSdkStoppedListener with the setOnSdkStoppedListener() method.

public static void setOnSdkStoppedListener(Glink.OnSdkStoppedListener onSdkStoppedListener);

the following is an example of using the PLUG closing listener.

   // PLUG closing listener settings
    Glink.setOnSdkStoppedListener(new Glink.OnSdkStoppedListener() {
      @Override public void onSdkStopped() {
        Toast.makeText(MainActivity.this, "CLOSE PLUG", Toast.LENGTH_LONG).show();
      }
    });

App scheme listener

onClickAppSchemeBannerListener is a callback listener that processes events that have occurred when pressing the banner image that goes to the App scheme.

Refer to “App scheme processing” for details about the App scheme.

처리할 작업은 setOnClickAppSchemeBannerListener() 메서드에 OnClickAppSchemeBannerListener를 등록해 구현한다.

public static void setOnClickAppSchemeBannerListener( OnClickAppSchemeBannerListener onClickAppSchemeBannerListener);

The following is an example of using the App scheme listener.

public static void setOnClickAppSchemeBannerListener( OnClickAppSchemeBannerListener onClickAppSchemeBannerListener)

   // App scheme listener settings
    Glink.setOnClickAppSchemeBannerListener(new Glink.OnClickAppSchemeBannerListener() {
      @Override public void onClickAppSchemeBanner(String appScheme) {
        // Deliver the appScheme text string, as set if cafe management, to the PLUG.
        // Run the code for processing each appScheme.
        Toast.makeText(MainActivity.this, appScheme, Toast.LENGTH_LONG).show();
      }
    });

Cafe registration listener

OnJoinedListener is a callback listener that processes events that have occurred when game users join the cafe on the PLUG.

Tasks that should be processed are carried out by registering onJoinedListener with the setOnJoinedListener() method.

public static void setOnJoinedListener(Glink.OnJoinedListener onJoinedListener);

The following is an example of using the cafe registration listener.

   // Cafe registration listener settings
    Glink.setOnJoinedListener(new Glink.OnJoinedListener() {
      @Override public void onJoined() {
        Toast.makeText(MainActivity.this, "카페에 가입하였습니다.", Toast.LENGTH_SHORT).show();
      }
    });

Post registration listener

OnPostedArticleListener is a callback listener that processes events that have occurred when users register posts on the PLUG.

Tasks that should be processed are carried out by registering OnPostedArticleListener with the setOnPostedArticleListener() method.

public static void setOnPostedArticleListener( Glink.OnPostedArticleListener onPostedArticleListener);

The following is an example of using the post registration listener.

   // Post registration listener settings
    Glink.setOnPostedArticleListener(new Glink.OnPostedArticleListener() {
      @Override public void onPostedArticle(int menuId, int imageCount, int videoCount) {
        String message = String.format("게시글이 작성되었습니다. (from listener, 메뉴: %d)", menuId);
        Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
      }
    });

Comment registration listener

OnPostedCommentListener is a callback listener that processes events that have occurred when users post comments on the PLUG.

Tasks that should be processed are carried out by registering OnPostedCommentListener with the setOnPostedCommentListener() method.

public static void setOnPostedCommentListener( Glink.OnPostedCommentListener onPostedCommentListener);

The following is an example of using the comment registration listener.

   // Comment registration listener settings
    Glink.setOnPostedCommentListener(new Glink.OnPostedCommentListener() {
      @Override public void onPostedComment(int articleId) {
        String message = String.format("Comments have been written. (from listener, posts: %d)", articleId);
        Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
      }
    });

Voting ended listener

OnVotedListener is a callback method that processes events that have occurred when users complete voting on comments on the PLUG.

Tasks that should be processed are carried out by registering OnVotedListener with the setOnVotedListener() method.

public static void setOnVotedListener(Glink.OnVotedListener listener);

The following is an example of using the voting ended listener.

   // Voting ended listener settings
    Glink.setOnVotedListener(new Glink.OnVotedListener() {
      @Override public void onVoted(int articleId) {
        String message = String.format("Voting has been completed. (from listener, posts: %d)", articleId);
        Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
      }
    });

Screen capture button click listener

OnWidgetScreenshotClickListener is a callback listener that processes events that have occurred when users pressed the screen capture button on the widget. Refer to "widget” for details about the screen capture button.

Tasks that should be processed are carried out by registering OnWidgetScreenshotClickListener with the setOnWidgetScreenshotClickListener() method.

public static void setOnWidgetScreenshotClickListener(Glink.OnWidgetScreenshotClickListener onWidgetScreenshotClickListener);

The following is an example of using the screen capture button click listener. By using the screen capture function on the callback listener, you can capture the screen when you press the screen capture button.

  //  Widget screen capture button click listener setting
  Glink.setOnWidgetScreenshotClickListener(new Glink.OnWidgetScreenshotClickListener() {
      @Override public void onScreenshotClick() {
        // TODO screen capture and run the PLUG (the following is sudo code)
        String uri = screenCapture();
        Glink.startImageWrite(getActivity(), "title", uri);
      }
    });

Recording ended listener

onRecordFinishListener is a callback listener that processes events that have occurred when video recording is ended on the PLUG.

Tasks that should be processed are carried out by registering OnRecordFinishListener with the setOnRecordFinishListener() method.

public static void setOnRecordFinishListener(OnRecordFinishListener onRecordFinishListener);

The following is an example of using the recording ended listener.

  // Recording ended listener settings
  Glink.setOnRecordFinishListener(new Glink.OnRecordFinishListener() {
      @Override public void onRecordFinished(String uri) {
        Glink.startVideoWrite(MainActivity.this, -1, "title", "subject", uri);
      }
    });

Game ID linkage

By linking the user’s game ID and cafe ID, they can be managed. You can check for the list of linked game ID and cafe IDs from cafe management menu.

In order to link a game ID and cafe ID, the syncGameUserId() method should be used.

public static void syncGameUserId(Activity activity, String gameUserId);

The following is an example of linking the game ID and cafe ID.

  /**
   * Link the game ID and cafe ID.
   */
  Glink.syncGameUserId(activity, "8263821")

Change theme color

You can change the theme color of the PLUG.

In order to change the theme color, the setThemeColor() method is used.

/** 
* The default value for the themeColorCSSString parameter is ‘#00c73c.’
 * The default value for backgroundCSSString parameter is ‘#44484e.’
 * It is recommended that you use the default value for the backgroundCSSString parameter.
**/

public static void setThemeColor(String themeColorCSSString);
public static void setThemeColor(String themeColorCSSString, String tabBackgroundColorCSSString)
  • themeColorCSSString: The default color that is used on the theme (default value: #00c73c)

  • backgroundCSSString: the background color for the tab menu (default value: #44484e). It is recommended that you use the default value.

Caution Do not apply alpha values for the CSS color value.

  • Correct example: #ff9800

  • Incorrect example: #e2ff9800

The following is an example of changing the theme color.

Glink.setThemeColor("#2e65d9"); 
Glink.setThemeColor("#2e65d9", "#44484e");

Change resource image

The resource image that is included in Naver cafe PLUG library can be changed as indicated below.

  1. Unzip the Naver cafe PLUG library file (.aar file).

  2. Change the image in the /res/drawable-xhdpi folder to the desired image.

  3. Compress the unzipped folder to a library file (.aar file).

  4. Apply the new Naver cafe PLUG library to build the project

Caution When changing the image, the new image's size should be identical with the previous image.

Last updated