Android SDKs

Prev Next

Available in Classic and VPC

This page describes how to use App Safer Android SDK for security of Android apps. You can integrate App Safer by installing the 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 APIs are provided through 1 package, and the APIs you can call from each package are as below.

start

Use the following code to run App Safer.

Note

As the start() function initiates network communication, calling it from the UI(Main) thread can cause an ANR. Calling it from a separate thread is recommended.

@Throws(AppSaferException::class)
fun start(context: Context)
void start(Context context) throws AppSaferException;
  • Parameter

    Parameter Description
    context ApplicationContext
  • Example

    runBlocking {
        AppSafer.INSTANCE.start(applicationContext)
    }
    
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            AppSafer.INSTANCE.start(getApplicationContext());
        }
    });
    thread.start(); 
    

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.

Note

This API must be configured before calling the start() function.

@Throws(AppSaferException::class)
fun setUserId(userId: String)
void setUserId(String userId) throws AppSaferException;
  • Parameter

    Parameter Description
    userId User identifier
  • Example

    AppSafer.INSTANCE.userId = "ExampleUserId"
    
    AppSafer.INSTANCE.setUserId("ExampleUserId");
    

getUserId

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

@Throws(AppSaferException::class)
fun getUserId(): String
String getUserId() throws AppSaferException;
  • Return value

    Return value Description
    String The set user identifier
  • Example

    val userId = AppSafer.INSTANCE.userId
    
    String userId = AppSafer.INSTANCE.getUserId();
    

getUserDeviceId

To view the Device identifier, use the below code.

@Throws(AppSaferException::class)
fun getUserDeviceId(): String
String getUserDeviceId() throws AppSaferException;
  • Return value

    Return value Description
    String Device identifier
  • Example

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

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.

@Throws(AppSaferException::class)
fun preventScreenshot(window: Window): Int
int preventScreenshot(Window window) throws AppSaferException;
  • Parameter

    Parameter Description
    window Window instance of the activity
  • Example

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