NowSDK - Android

  • 릴리스 버전: Australia
  • 업데이트 날짜 2026년 03월 12일
  • 소요 시간: 4분
  • The NowSDK class is a singleton that provides the public API for the NowSDK. This class is the gateway to all Android SDK feature services.

    Before initializing a feature service, you must initialize the SDK itself by calling NowSDK.configure(). For additional information on getting started with the Android NowSDK, refer to the ServiceNow Mobile SDK Developers Guide - Android.

    NowSDK - configure(application: Application, configuration: NowSDKConfiguration)

    Configures the NowSDK for use.

    You must call this function before attempting to use any of the feature services provided by the SDK.

    표 1. Parameters
    Name Type Description
    application Application Reference to the hosting application object.
    configuration NowServiceConfiguration Object containing the information necessary to initialize the NowSDK.
    표 2. Returns
    Type Description
    None NowSDKError is thrown if the provided configuration is invalid.

    The following code example shows how to call this function.

    class SampleApplication : Application(), NowSDKAuthorizationProviding, DevicePermissionDelegate {
    
        private val nowSdkSettings = NowSDKSettings(
            instanceBaseURL = "https://instance-name.service-now.com",
            clientId = "client_id",
            user = "user"
        )
    
        private val coroutineScope = CoroutineScope(Dispatchers.IO)
    
        private val nowSDKConfiguration = NowSDKConfiguration(this, this, NowLogLevel.Debug)
        override fun onCreate() {
            super.onCreate()
    
            NowSDK.configure(this, nowSDKConfiguration)
        }
    
    
        override fun requestAuthorization(
            instanceURL: URL,
            callback: Consumer<List<AuthorizationToken>?>
        ) {
            coroutineScope.launch {
                when {
                    nowSdkSettings.user.isNullOrBlank().not() -> authorizeWithJWT(
                        callback = callback,
                        user = nowSdkSettings.user,
                        clientId = nowSdkSettings.clientId
                    )
    
                    else -> authorizeWithGuest(callback = callback)
                }
            }
        }
    
        override fun canRequestPermission(permission: DevicePermission): Boolean {
            return true
        }
    }

    NowSDK - logout()

    Clears all user sessions persisted in memory.

    표 3. Parameters
    Name Type Description
    None
    표 4. Returns
    Type Description
    None

    The following code example shows how to call this function.

    class SampleApplication : Application() {
    
        private val nowSDKConfiguration = NowSDKConfiguration(authorizationProvider, permissionDelegate, NowLogLevel.Debug)
    
        override fun onCreate() {
            super.onCreate()
            NowSDK.configure(this, nowSDKConfiguration)
        }
    
        fun logout() {
            // Clear all user session when an application resets the user session
            NowSDK.logout()
        }
    }