Android SDK v1

Prev Next

Available in Classic and VPC

In Using Android SDK v1, it describes how to use Android SDK v1, which is provided by Effective Log Search & Analytics 2.0 service.

The following describes how to use SDK.

1. Preparation
2. Install SDK
3. Initialize SDK
4. Add permission for SDK
5. Use SDK

1. Preparation

The following describes the preparations for installing Android SDK.

  1. In NAVER Cloud Platform's console, Create project.
  2. Check the txtToken value in Project detail page.
  3. Download Android SDK v1.

2. Install Android SDK v1

The following describes how to install Android SDK v1.

  1. Unzip the downloaded SDK file.
  2. Save the SDK file in the libs folder of the Android project where SDK is to be installed.
    • When using the Thrift protocol: save nelo2-android-sdk-common-SDK버전명.jar and nelo2-android-sdk-thrift-SDK버전명.jar files
    • When using the HTTPS protocol: save nelo2-android-sdk-common-SDK버전명.jar and nelo2-android-sdk-https-SDK버전명.jar files
    • Starting from NELO SDK 0.9.0, the library files to be added to the libs folder are different depending on the protocol.
    • <example>
      .....
      android {
          compileOptions {
              sourceCompatibility JavaVersion.VERSION_1_8
              targetCompatibility JavaVersion.VERSION_1_8
          }
      }
      .....
      repositories{
          flatDir{
              dirs 'libs'
          }
      }
      .....
      dependencies {
          implementation (name: 'nelo2-android-sdk-common', version: '0.12.0', ext: 'aar')
          implementation (name: 'nelo2-android-sdk-https', version: '0.12.0', ext: 'aar')
          implementation (name: 'nelo2-android-sdk-thrift', version: '0.12.0', ext: 'aar')
          implementation (name: 'tink-android', version: '1.4.0', ext: 'jar')
      }
      .....
      

3. Initialize Android SDK v1

You can initialize Effective Log Search & Analytics 2.0 Android SDK in the following two ways.

  • Call init method at the Main Activity
    • Transfer logs without creating a crash dialog when an app crash occurs
    • <example>
      public class MainActivity extends Activity {
      
          .....
      
          @Override
      
          protected void onCreate(Bundle savedInstanceState) {
      
              .....
      
              NeloLog.init(getApplication(), "elsa-col.ncloud.com", 10006, "__Project_ID__", "__ProjectVersion__");
      
              .....
      
          }
      
      }
      
  • Call init method at Application
    • @NeloConf Use along with the annotation
    • Export a crash dialog transferring the crash log following the settings when an app crash occurs
    • <example>
      @NeloConf(
          collectorUrl = "elsa-col.ncloud.com",                   // Effective Log Search & Analytics 2.0 Collector URL   (required)
          serverPort = Nelo2Constants.SERVER_PORT_THRIFT,         // Effective Log Search & Analytics 2.0 Port Number     (required)
          projectName = "72356c50401b8e20_testproject",           // Effective Log Search & Analytics 2.0 Project ID     (required)
          mode = CrashReportMode.DIALOG,                          // Effective Log Search & Analytics 2.0 CrashReportMode (optional, Default : SLIENT)
          sendMode = NeloSendMode.ALL,                            // Effective Log Search & Analytics 2.0 SendMode        (optional, Default : ALL)
          debug = true,                                           // Effective Log Search & Analytics 2.0 Debug mode      (optional, Default : false)
          logSource = "elsa-android",                             // Effective Log Search & Analytics 2.0 Log Source      (optional, Default : nelo2-android)
          logType = "development",                                // Effective Log Search & Analytics 2.0 Log Type        (optional, Defalut : nelo2-log)
          resDialogText = R.string.crash_dialog_text,             // Crash Report Doalog Text     (required, if you set mode CrashReportMode.Dialog)
          resDialogTitle = R.string.crash_dialog_title            // Crash Report Dolog Title    (required, if you set mode CrashReportMode.Dialog)
      )
      public class MainApplication extends Application {
          .....
          @Override
          protected void onCreate() {
              .....
              NeloLog.init(this);
              .....
          }
      }
      .....
      
Note
  • For more information on initialization method, see Initialization API.
  • Initialize by calling init method at Application is recommended.

4. Add permission for Android SDK v1

You need to add permission to import information, such as network status, device information, telecommunications company, and Logcat. Add the following content to the AndroidManifest.xml file.

.....
/** AndroidManifest.xml **/
    <!-- Permission for the Internet access to transfer Nelo log (Required) -->
    <uses-permission android:name="android.permission.INTERNET"/>

    <!-- Permission to access information of the mobile phone, such as platform and carrier (Required) -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <!-- Permission to access Network access (Required) -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <!-- Permission to save data as files when network access is not allowed -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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

      <!-- Need to set a name if the application is created to use the Crash Report Dialog-->
       <application ..... android:name="ApplicationName">
.....

       <!-- Receiver that should be added to send logs only when the network status is WiFi mode by checking the network status -->
    <!-- No need to add it when using the SendMode as All -->
    <receiver android:name="com.nhncorp.nelo2.android.util.NetworkStatusReceiver">
        <intent-filter>
               <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
        </intent-filter>
    </receiver>
.....

<!-- Activity to use the Crash Report Dialog -->
<!-- No need to add it when not using CrashReportMode.DIALOG -->
<activity android:name="com.nhncorp.nelo2.android.CrashReportDialog"
    android:theme="@android:style/Theme.Dialog"
    android:launchMode="singleInstance"
    android:excludeFromRecents="true"
    android:finishOnTaskLaunch="true" />
.....

5. Use SDK

Refer to the following actual codes that use Effective Log Search & Analytics 2.0 Android SDK and transfer logs to the projects.

.....
import com.nhncorp.nelo2.android.NeloLog;
.....

public class MainActivity extends Activity {
.....
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        NeloLog.init(getApplication(),"ELSA-COLLECTOR-URL",10006,"ELSA-PROJECT-ID","PROJECT-VERSION");
        NeloLog.debug("ErrorCode","Message","ErrorLocation");   // Send Debug Message
        NeloLog.info("ErrorCode","Message","ErrorLocation");    // Send Info Message
        NeloLog.warn("ErrorCode","Message","ErrorLocation");    // Send Warn Message
        NeloLog.error("ErrorCode","Message","ErrorLocation");   // Send Error Message
        NeloLog.fatal("ErrorCode","Message","ErrorLocation");   // Send Fatal Message
        String nullString = null;
        try{
            nullString.toString();
        }catch(Exception e){
            NeloLog.crash(e,"ErrorCode","Message","ErrorLcoation"); // Send caught crash Message
        }

        NeloLog.debug("ErrorCode","Message","ErrorLocation");   // Send message with custom message
        int i = 10 / 0;     // Nelo send uncaught exception
    }
.....

Android SDK v1 API details

Android SDK v1 provides the following API.

Initialization API

Android SDK v1 provides initialization method for each calling method.

Note
  • You need to initialize NeloLog first before using NeloLog to make it work normally. Initialize only one time.
  • You need to initialize at Application to use Crash Report Dialog.

Initialize at Main Activity

Here are the APIs that should be initialized at Main Activity.

static boolean init(Application application, String reportServer, int projectName, String appId, String projectVersion)
static boolean init(Application application, String reportServer, int projectName, String appId, String projectVersion, String userId)

The following describes each parameter.

Parameter Description
Application application Android's application information
  • Normally uses getApplication()
String reportServer Log collecting server's address
  • Thrift: elsa-col.ncloud.com
  • HTTPS: https://elsa-col.ncloud.com/_store
int serverPort Log collecting server's port information
  • Thrift: 10006
  • Https: 443
String appId Project key (Refer to Project details)
String appVersion Version information of the app to transfer logs
String userId User ID to transfer (Optional)

<example>

NeloLog.init(getApplication(), "elsa-col.ncloud.com", 10006, "72356c50401b8e20_testproject", "1.0.0");

Initialization at Application

Here are the APIs that should be initialized at Application. You must enter the @NeloConf annotation together.

boolean init (Application application)

The following describes each parameter.

Parameter Description
Application application Android's application information. In general, enter getApplication()

<example>

@NeloConf(

    collectorUrl = "elsa-col.ncloud.com",      // NELO Collector URL   (required)

    serverPort = Nelo2Constants.SERVER_PORT_THRIFT,         // NELO Port Number     (required)

    projectName = "72356c50401b8e20_testproject",           // NELO Project ID      (required)

    mode = CrashReportMode.DIALOG,                          // NELO CrashReportMode (optional, Default : SLIENT)

    sendMode = NeloSendMode.ALL,                            // NELO SendMode        (optional, Default : ALL)

    debug = true,                                           // NELO Debug mode      (optional, Default : false)

    logSource = "elsa-android",   // NELO Log Source      (optional, Default : nelo2-android)

    logType = "development",            // NELO Log Type        (optional, Defalut : nelo2-log)

    resDialogText = R.string.crash_dialog_text,             // Crash Report Doalog Text     (required, if you set mode CrashReportMode.Dialog)

    resDialogTitle = R.string.crash_dialog_title            // Crash Report Doalog Title    (required, if you set mode CrashReportMode.Dialog)

)

public class MainApplication extends Application {

    .....

    @Override

    protected void onCreate() {

        .....

        NeloLog.init(this);

        .....

    }

}

.....

System Field setting API

Here are the APIs that set the System Field value. The value you set will be forwarded equally from all logs that will be transferred in the future.

Set user ID

Here are the APIs that set user ID.

static void void setUserID(String userID)

The following describes each parameter.

Parameter Description
String userID User ID

<example>

NeloLog.setUserID("test");

Set logSource information

Here are the APIs that set logSource.

static void setLogSource(String logSource)
static void setLogSource(String instanceName, String logSource)

The following describes each parameter.

Parameter Description
String logSource logSource information
String instanceName Dynamic instance name

<example>

NeloLog.setLogSource("NELO2 Android SDK LogSource");

Set log type

Here are the APIs that set logType.

static void setLogType(String logType)
static void setLogType(String instanceName, String logType)

The following describes each parameter.

Parameter Description
String logType logType information
String instanceName Dynamic instance name

<example>

NeloLog.setLogType("NELO2 Android SDK LogType");

Log transferring API

Here are the APIs that transfer logs.

Note

Uses functions by logLevel.

  • logLevel: Fatal, Error, Warn, Info, and Debug
static void debug(String errorCode,String message,String location)
static void debug(String errorCode,String message)
static void info(String errorCode,String message,String location)
static void info(String errorCode,String message)
static void warn(String errorCode,String message,String location)
static void warn(String errorCode,String message)
static void error(String errorCode,String message,String location)
static void error(String errorCode,String message)
static void fatal(String errorCode,String message,String location)
static void fatal(String errorCode,String message)

The following describes each parameter.

Parameter Description
String errorCode The value that is mapped to NELO's errorCode field
String message The value that is mapped to NELO's body
String location Location where the log occurred

<example>

NeloLog.error("test","testvalue","location");
NeloLog.debug("test 2","testvalue ")

Log transferring API (including exceptions)

Here are the APIs that transfer logs including exception information.

Transfer error logs

Here are the APIs that transfer error logs including exception information.

Note

Uses functions by logLevel.

  • logLevel: Fatal, Error, Warn, Info, and Debug
static void debug(Throwable t, String errorCode,String message,String location)
static void debug(Throwable t, String errorCode,String message)
static void info(Throwable t, String errorCode,String message,String location)
static void info(Throwable t, String errorCode,String message)
static void warn(Throwable t, String errorCode,String message,String location)
static void warn(Throwable t, String errorCode,String message)
static void error(Throwable t, String errorCode,String message,String location)
static void error(Throwable t, String errorCode,String message)
static void fatal(Throwable t, String errorCode,String message,String location)
static void fatal(Throwable t, String errorCode,String message)

// For transferring dynamic instance logs
static void debugWithInstanceName(String instanceName, Throwable t, String errorCode, String message)
static void debugWithInstanceName(String instanceName, Throwable t, String errorCode, String message, String errorLocation)
static void infoWithInstanceName(String instanceName, Throwable t, String errorCode, String message)
static void infoWithInstanceName(String instanceName, Throwable t, String errorCode, String message, String errorLocation)
static void warnWithInstanceName(String instanceName, Throwable t, String errorCode, String message)
static void warnWithInstanceName(String instanceName, Throwable t, String errorCode, String message, String errorLocation)
static void errorWithInstanceName(String instanceName, Throwable t, String errorCode, String message)
static void errorWithInstanceName(String instanceName, Throwable t, String errorCode, String message, String errorLocation)
static void fatalWithInstanceName(String instanceName, Throwable t, String errorCode, String message)
static void fatalWithInstanceName(String instanceName, Throwable t, String errorCode, String message, String errorLocation)

The following describes each parameter.

Parameter Description
Throwable t Exception information
  • When setting Throwable information, a field named Cause is saved, and the getCause() value is saved
String errorCode The value that is mapped to NELO's errorCode field
String message The value that is mapped to NELO's body
String location Location where the log occurred
  • If the location information is not set, Throwable saves the location of the error at location

<example>

try{

    int a = 10 / 0;

} catch (Exception e) {

    NeloLog.error(e,"Error_Code",e.getMessage());

}

Transfer crash logs

Here are the APIs that transfer crash logs including exception information in exceptional instances.

Note
  • As soon as the user calls the crash function, the crash log and DmpData field are transferred to NELO.
  • Call only when it is necessary for the app's performance (Recommended).
static void crash(Throwable t, String errorCode,String message,String location)
static void crash(Throwable t, String errorCode,String message)

<example>

try{
    int a = 10 / 0;

} catch (Exception e) {

    NeloLog.crash(e,"Error_Code",e.getMessage());

}

Crash callback API

You can call the user-defined functions before sending the crash log when a crash occurs. Here are the crash callback APIs.

static void setNeloCrashCallback(NeloCrashCallback neloCrashCallback)

The following describes each parameter.

Parameter Description
NeloCrashCallback neloCrashCallback Function called when a crash occurs
  • boolean beforeSendNeloCrash()
    • Determines whether to transfer the crash log as the return value
  • boolean beforeInstanceSendNeloCrash(String instanceName) (currently not supported)
    • When several instances are created and logs for certain instances are transferred, determine it as the return value by comparing it with the instanceName value
    • When it is initialized with the NeloLog.init(), set the name as Nelo2Constants.NELO_DEFAULT_INSTANCE_NAME
  • void finishInstanceSendNeloCrash(String instanceName) (currently not supported)
    • Calls when log transfer for certain instances is completed
  • void finishSendNeloCrash()
    • Calls when the entire crash transfer is completed

<example>

NeloLog.setNeloCrashCallback(new NeloCrashCallback() {
        @Override
        public boolean beforeSendNeloCrash() {
            Log.e("[AndroidApp]", "______________[[ beforeSendNeloCrash ]]__________________");
            return true;
        }

        @Override
        public boolean beforeInstanceSendNeloCrash(String instanceName) {
            Log.e("[AndroidApp]", "______________[[ beforeInstanceSendNeloCrash ]   " + instanceName + "]__________________");
            return Nelo2Constants.NELO_DEFAULT_INSTANCE_NAME.equalsIgnoreCase(instanceName);
        }

        @Override
        public void finishInstanceSendNeloCrash(String instanceName) {
            Log.e("[AndroidApp]", "______________[[ finishInstanceSendNeloCrash ]   " + instanceName + "]__________________");
        }

        @Override
        public void finishSendNeloCrash() {
            Log.e("[AndroidApp]", "______________[[ finishSendNeloCrash ]]__________________");
        }
    });

Option setting API

Here are the Option setting APIs.

Set whether to use NELO

Here are the APIs that set whether to use NELO.

static boolean getNeloEnable()
static void setNeloEnable(boolean enabled)

The following describes each parameter.

Parameter Description
boolean enabled Set whether to use NELO
  • If you set it as false, all log transfer and file saving features are ceased

Set whether to use the Debug mode

When the Debug mode is used, detailed logs for Logcat are recorded. Here are the APIs that set whether to use Debug mode.

static boolean getDebug()
static void setDebug(boolean enabled)

The following describes each parameter.

Parameter Description
boolean enabled Whether to use Debug mode
  • Set it as true only in a testing environment, and set it as false in the operating environment

Set crash transfer method

Here are the APIs that set crash transfer method.

static CrashReportMode getCrashMode()
static void setCrashMode(CrashReportMode mode)

The following describes each parameter.

Parameter Description
CrashReportMode mode Set crash transfer method when an app crash occurs
  • It is linked to the AndroidManifest.xml file's CrashReportDialog
  • CrashReportMode.NONE: does not transfer crash when an app crash occurs
  • CrashReportMode.SLIENT: does not notify the user when an app crash occurs and transfers the crash log
  • CrashReportMode.DIALOG: shows Crash Report Dialog to the user when an app crash occurs, and transfers crash only when the user approves
    • It is linked to the following items of the @NeloConf's annotation
      • resDialogTitle: title of the Crash Report Dialog. String ID defined in res/values/string.xml
      • resDialogText: Crash Report Dialog's description. String ID defined in res/values/string.xml

Set log transfer method

Here are the APIs that set log transfer method.

static NeloSendMode getNeloSendMOde()
static void setNeloSendMOde(NeloSendMode mode)

The following describes each parameter.

Parameter Description
NeloSendMode mode Set log transfer method

The following shows the log transfer method by network, depending on the parameter setting value.

  • ALL

    Network status Transfer method
    3g Transfer
    Wi-Fi Transfer
    Not Connected Not transferred, saving file
  • ONLY_WIFI_WITH_FILE_SAVE

    Network status Transfer method
    3g Not transferred, saving file
    Wi-Fi Transfer
    Not Connected Not transferred, saving file
  • ONLY_WIFI_WITHOUT_FILE_SAVE

    Network status Transfer method
    3g Not transferred, not saving file
    Wi-Fi Transfer
    Not Connected Not transferred, not saving file
Note

When setting ONLY_WIFI_WITH_FILE_SAVE or ONLY_WIFI_WITHOUT_FILE_SAVE, you need to add permission to check the network status. (Refer to Add permission for Android SDK v1)

Set the maximum file size of the log save file

Here are the APIs that set the maximum file size of the log save file.

Note
  • Default of the maximum file size of the log save file is 1 MB (1024 x 1024 bytes).
  • When the log file's size is larger than the maximum value, it is saved after deleting old data.
  • For how to set logs to be saved as files, see Set log transfer method.
static int getMaxFileSize()
static void setMaxFileSize(int max_file_size)
static int getMaxFileSize(String instanceName)
static void setMaxFileSize(String instanceName, int max_file_size)

The following describes each parameter.

Parameter Description
int max_file_size The maximum file size of the log save file
String instanceName Dynamic instance name

Transfer logs saved in the queue and files to the server

Here are the APIs that transfer logs temporarily saved in the queue and files to the server.

static void flush()

View the current size of the log save file

Here are the APIs that view (return) the total size of the files used by the current NELO logs.

static long getAllNeloSaveLogFileSize()

Set whether to transfer previous files to the server

Here are the APIs that set whether to read previous files and transfer them to the server.

Note
  • Use the file name created with a hash value by combining InstanceName and the project name.
  • Call this function when you have to delete existing files because the project name and instance name have changed.
  • When the flushFile value is true (default value), read all the content before deleting the previous files and save them in the queue.
static boolean clearSavedNeloLogFile(boolean flushFile)

The following describes each parameter.

Parameter Description
boolean flushFile Determines whether to read previous files and transfer them to the server

Set loglevel

Here are the APIs that transfer logs over the loglevel.

Note
  • The default is Nelo2LogLevel.DEBUG.
  • When the user makes requests to transfer logs to the server explicitly, such as crash or flush, ignore LogLevel's filter value.
static Nelo2LogLevel getLogLevelFilter()
static void setLogLevelFilter(Nelo2LogLevel loglevel)

The following describes each parameter.

Parameter Description
Nelo2LogLevel loglevel Transfers logs over loglevel to NELO