Android SDK
    • PDF

    Android SDK

    • PDF

    Article Summary

    Available in Classic and VPC

    This page describes how to use App Safer Android SDK for security of Android apps. You can connect App Safer by installing SDK and configuring the environment.

    Note

    For general sample codes for applying App Safer, see Sample Code.

    SDK installation and environment configuration

    To use the features provided by App Safer, first install the Android SDK and configure the environment. The following describes how to configure them.

    1. Open the app project on the developer tools.

    2. Copy the AAR file downloaded from the NAVER Cloud Platform console to the libs file of project.

      • If there is no libs folder, create one.
    3. Open the build.gradle file and add the below code.

      repositories {
          flatDir {
              dirs 'libs'
          }
      }
      
    4. Add the below code to the build.gradle file and set the dependency on the App Safer AAR file.

      • Set to refer to only a specific version
        dependencies {
            implementation name:'appsafer-android-sdk-${vesion}', ext:'aar'
        }
        
      • Set to refer to all versions
        dependencies {
            implementation fileTree(dir: 'libs', include: 'appsafer-android-sdk-*.aar')
        }
        
    5. Open the AndroidManifest.xml file and use the meta-data tag to apply permissions and enter the App Safer Key.

      • In the meta-data tag, the android:name value must be prepared as com.ncp.appsafer.key.
      • android.permission.INTERNET is a required permission. If there is no permission in the file, add the code.
      <?xml version="1.0" encoding="utf-8"?>
      <manifest>
          <uses-permission android:name="android.permission.INTERNET"/>
      
          <!-- required permission for Antivirus(target API >= 30) -->
          <uses-permission
              android:name="android.permission.QUERY_ALL_PACKAGES"
              tools:ignore="QueryAllPackagesPermission" />
      
          <application>
              <meta-data
                  android:name="com.ncp.appsafer.key"
                  android:value="{APPSAFER_KEY}" />
          </application>
      </manifest>
      

    Provided APIs

    The App Safer API is provided through 1 package, and the API you can call from each package is as below.

    start

    Use the following code to run App Safer.

    fun start(context: Context): Int
    
    int start(Context context)
    
    • Parameter

      ParameterDescription
      contextApplicationContext
    • Return value

      Return valueDescription
      EXIT_SUCCESS(-1)Execution failed
      EXIT_FAILURE(0)Execution succeeded
    • Example

      if (AppSafer.INSTANCE.start(applicationContext) == 0) {
          // success logic
      }
      
      if (AppSafer.INSTANCE.start(getApplicationContext()) == 0) {
          // success logic
      }
      

    setUserId

    When a reset and detection event occur, if you want to include a user identifier in a log transmitted to the App Safer server, use the below code.

    fun setUserId(userId: String)
    
    void setUserId(String userId)
    
    • Parameter

      ParameterDescription
      userIdUser identifier
    • Example

      • SDK

        AppSafer.INSTANCE.userId = "ExampleUserId"
        
        AppSafer.INSTANCE.setUserId("ExampleUserId");
        
      • Simple application

        val exampleId = "exampleId"
        val clazz = Class.forName("com.nbp.appsafer.AppSafer")
        val enumConstants = clazz.enumConstants
        if ("INSTANCE" == enumConstants[0].toString()) {
            clazz.getDeclaredMethod("setUserId", String::class.java).invoke(enumConstants[0], userId)
        }
        
        final String userId = "exampleId";
        Class<?> clazz = Class.forName("com.nbp.appsafer.AppSafer");
        Object[] enumConstants = clazz.getEnumConstants();
        if ("INSTANCE".equals(enumConstants[0].toString())) {
            clazz.getDeclaredMethod("setUserId", String.class).invoke(enumConstants[0], userId);
        }
        

    getUserId

    To view the set user identifier, use the below code.

    fun getUserId(): String
    
    String getUserId()
    
    • Return value

      Return valueDescription
      StringSet user identifier
    • Example

      • SDK

        val userId = AppSafer.INSTANCE.userId
        
        String userId = AppSafer.INSTANCE.getUserId();
        
      • Simple application

        var userId: String? = null
        val clazz = Class.forName("com.nbp.appsafer.AppSafer")
        val enumConstants = clazz.enumConstants
        if ("INSTANCE" == enumConstants[0].toString()) {
            userId = clazz.getDeclaredMethod("getUserId").invoke(enumConstants[0]) as String?
        }
        
        String userId = null;
        Class<?> clazz = Class.forName("com.nbp.appsafer.AppSafer");
        Object[] enumConstants = clazz.getEnumConstants();
        if ("INSTANCE".equals(enumConstants[0].toString())) {
            userId = (String) clazz.getDeclaredMethod("getUserId").invoke(enumConstants[0]);
        }
        

    getUserDeviceId

    To view the Device identifier, use the below code.

    fun getUserDeviceId(): String
    
    String getUserDeviceId()
    
    • Return value

      Return valueDescription
      StringDevice identifier
    • Example

      • SDK

        val userId = AppSafer.INSTANCE.userDeviceId
        
        String userDeviceId = AppSafer.INSTANCE.getUserDeviceId();
        
      • Simple application

        var udid: String? = null
        val clazz = Class.forName("com.nbp.appsafer.AppSafer")
        val enumConstants = clazz.enumConstants
        if ("INSTANCE" == enumConstants[0].toString()) {
            udid = clazz.getDeclaredMethod("getUserDeviceId").invoke(enumConstants[0]) as String?
        }
        
        String udid = null;
        Class<?> clazz = Class.forName("com.nbp.appsafer.AppSafer");
        Object[] enumConstants = clazz.getEnumConstants();
        if ("INSTANCE".equals(enumConstants[0].toString())) {
            udid = (String) clazz.getDeclaredMethod("getUserDeviceId").invoke(enumConstants[0]);
        }
        

    preventScreenshot

    To limit the screenshot, recording, and preview latest apps features of the app, use the below code.

    Note

    Call by the unit of activity.

    fun preventScreenshot(window: Window): Int
    
    int preventScreenshot(Window window)
    
    • Parameter

      ParameterDescription
      windowWindow instance of the activity
    • Example

      AppSafer.INSTANCE.preventScreenshot(window)
      
      AppSafer.INSTANCE.preventScreenshot(getWindow());
      

    Was this article helpful?

    What's Next
    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.