- Print
- PDF
Android SDK
- Print
- PDF
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.
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.
Open the app project on the developer tools.
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.
Open the build.gradle file and add the below code.
repositories { flatDir { dirs 'libs' } }
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') }
- Set to refer to only a specific version
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, theandroid:name
value must be prepared ascom.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>
- In the
Provided APIs
The App Safer API is provided through 1 package, and the API you can call from each package is as below.
com.nbp.appsafer.AppSafer
Name Description start Run App Safer setUserId Set user identifier getUserId Search the set user identifier getUserDeviceId Search the device identifier preventScreenshot Capture prevention
start
Use the following code to run App Safer.
fun start(context: Context): Int
int start(Context context)
Parameter
Parameter Description context ApplicationContext Return value
Return value Description 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
Parameter Description userId User 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 value Description String Set 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 value Description String Device 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.
Call by the unit of activity.
fun preventScreenshot(window: Window): Int
int preventScreenshot(Window window)
Parameter
Parameter Description window Window instance of the activity Example
AppSafer.INSTANCE.preventScreenshot(window)
AppSafer.INSTANCE.preventScreenshot(getWindow());