Data Fetching Guide for Android

    Airbridge Device ID

    Device identifier by Airbridge. (example: 82a16ec9-a273-48b6-9bb2-017eab641109)

    Android SDK (v4)

    123456789101112
    import co.ab180.airbridge.Airbridge
    import co.ab180.airbridge.common.onSuccess
    import co.ab180.airbridge.common.onFailure
    
    Airbridge.fetchDeviceUUID(
        onSuccess = { deviceUUID ->
    
        },
        onFailure = { throwable ->
    
        }
    )

    Android SDK (Previous)

    123456789101112
    import co.ab180.airbridge.Airbridge
    import co.ab180.airbridge.AirbridgeCallback
    
    Airbridge.getDeviceInfo().getUUID(object : AirbridgeCallback.SimpleCallback<String>() {
            override fun onSuccess(result: String) {
      
        }
    
        override fun onFailure(throwable: Throwable) {
      
        }
    })

    Airbridge Generated UUID

    Random UUID assigned by Airbridge upon app install on each device. (example: 82a16ec9-a273-48b6-9bb2-017eab641109)

    Android SDK (v4)

    123456789101112
    import co.ab180.airbridge.Airbridge
    import co.ab180.airbridge.common.onSuccess
    import co.ab180.airbridge.common.onFailure
    
    Airbridge.fetchAirbridgeGeneratedUUID(
        onSuccess = { airbridgeGeneratedUUID ->
    
        },
        onFailure = { throwable ->
    
        }
    )

    Android SDK (Previous)

    12345
    import co.ab180.airbridge.Airbridge
    
    Airbridge.fetchAirbridgeGeneratedUUID { uuid ->
    
    }

    App Set ID

    Unique ID that publishers can use to identify which apps a specific user has installed. (example: 82a16ec9-a273-48b6-9bb2-017eab641109)

    123456789101112
    import com.google.android.gms.appset.AppSet
    import com.google.android.gms.appset.AppSetIdClient
    import com.google.android.gms.appset.AppSetIdInfo
    import com.google.android.gms.tasks.Task
    
    val client = AppSet.getClient(applicationContext) as AppSetIdClient
    val task: Task<AppSetIdInfo> = client.appSetIdInfo as Task<AppSetIdInfo>
    
    task.addOnSuccessListener({
        val appSetIdScope: Int = it.scope
        val appSetId: String = it.id
    })

    GAID (Google Advertising ID)

    Advertising ID issued by Google. (example: 82a16ec9-a273-48b6-9bb2-017eab641109)

    1234567891011121314
    import co.ab180.airbridge.Airbridge
    import co.ab180.airbridge.AirbridgeCallback
    import co.ab180.airbridge.AdvertisingIdInfo
    
    Airbridge.getDeviceInfo().getAdvertisingIdInfo(object : AirbridgeCallback.SimpleCallback<AdvertisingIdInfo>() {
            override fun onSuccess(result: AdvertisingIdInfo) {
                result.getId() // GAID
            result.getLimitAdTrackingEnabled() // LAT
        }
    
        override fun onFailure(throwable: Throwable) {
      
        }
    })

    Google Limit AD Tracking

    Device's Google Limit AD Tracking information. (example: true)

    1234567891011121314
    import co.ab180.airbridge.Airbridge
    import co.ab180.airbridge.AirbridgeCallback
    import co.ab180.airbridge.AdvertisingIdInfo
    
    Airbridge.getDeviceInfo().getAdvertisingIdInfo(object : AirbridgeCallback.SimpleCallback<AdvertisingIdInfo>() {
            override fun onSuccess(result: AdvertisingIdInfo) {
                result.getId() // GAID
            result.getLimitAdTrackingEnabled() // LAT
        }
    
        override fun onFailure(throwable: Throwable) {
      
        }
    })

    Google Install Referrer

    InstallReferrer information sent by Google Play Service.

    1234567891011121314151617
    import co.ab180.airbridge.Airbridge
    import co.ab180.airbridge.AirbridgeCallback
    import co.ab180.airbridge.ReferrerDetails
      
    Airbridge.getDeviceInfo().getGoogleInstallReferrerDetails(object : AirbridgeCallback<ReferrerDetails?> {
      override fun onSuccess(result: ReferrerDetails?) {
      
      }
      
      override fun onFailure(throwable: Throwable) {
    
      }
      
      override fun onComplete() {
      
      }
    })

    OAID (Huawei Advertising ID)

    Advertising ID issued by Huawei. (example: 82a16ec9-a273-48b6-9bb2-017eab641109)

    1234567891011121314
    import co.ab180.airbridge.Airbridge
    import co.ab180.airbridge.AirbridgeCallback
    import co.ab180.airbridge.AdvertisingIdInfo
    
    Airbridge.getDeviceInfo().getHuaweiAdvertisingIdInfo(object : AirbridgeCallback.SimpleCallback<AdvertisingIdInfo>() {
            override fun onSuccess(result: AdvertisingIdInfo) {
                result.getId() // OAID
            result.getLimitAdTrackingEnabled() // LAT
        }
    
        override fun onFailure(throwable: Throwable) {
      
        }
    })

    Huawei Limit AD Tracking

    Device's Huawei Limit AD Tracking information. (example: true)

    1234567891011121314
    import co.ab180.airbridge.Airbridge
    import co.ab180.airbridge.AirbridgeCallback
    import co.ab180.airbridge.AdvertisingIdInfo
    
    Airbridge.getDeviceInfo().getHuaweiAdvertisingIdInfo(object : AirbridgeCallback.SimpleCallback<AdvertisingIdInfo>() {
            override fun onSuccess(result: AdvertisingIdInfo) {
                result.getId() // OAID
            result.getLimitAdTrackingEnabled() // LAT
        }
    
        override fun onFailure(throwable: Throwable) {
      
        }
    })

    Huawei Install Referrer

    InstallReferrer information sent by Huawei Mobile Service.

    1234567891011121314151617
    import co.ab180.airbridge.Airbridge
    import co.ab180.airbridge.AirbridgeCallback
    import co.ab180.airbridge.ReferrerDetails
      
    Airbridge.getDeviceInfo().getHuaweiInstallReferrerDetails(object : AirbridgeCallback<ReferrerDetails?> {
      override fun onSuccess(result: ReferrerDetails?) {
      
      }
      
      override fun onFailure(throwable: Throwable) {
    
      }
      
      override fun onComplete() {
      
      }
    })

    One Store Install Referrer

    InstallReferrer information sent by One Store.

    1234567891011121314151617
    import co.ab180.airbridge.Airbridge
    import co.ab180.airbridge.AirbridgeCallback
    import co.ab180.airbridge.ReferrerDetails
      
    Airbridge.getDeviceInfo().getOneStoreInstallReferrerDetails(object : AirbridgeCallback<ReferrerDetails?> {
      override fun onSuccess(result: ReferrerDetails?) {
      
      }
      
      override fun onFailure(throwable: Throwable) {
    
      }
      
      override fun onComplete() {
      
      }
    })

    Device Model

    Device model name. (example: Pixel 3a)

    123
    import android.os.Build
    
    Build.MODEL // ex : Pixel 3a

    Device Manufacturer

    Device manufacturer information. (example: Google)

    123
    import android.os.Build
    
    Build.MANUFACTURER // ex : Google

    OS Version

    Device OS version. (example: 10)

    123
    import android.os.Build
    
    Build.VERSION.RELEASE // ex : 10

    Locale

    Device locale settings. (example: en-US)

    1234
    import java.util.*
    
    // ex : en-US
    "${Locale.getDefault().language}-${Locale.getDefault().country}"

    Timezone

    Device timezone settings. (example: US/Pacific)

    123
    import java.util.*
    
    TimeZone.getDefault().id // ex : US/Pacific

    Orientation

    Device display orientation. Values will be either "portrait" or "landscape". (example: portrait)

    123456789
    import android.content.res.Configuration
    import android.content.Context
    
    var orientation: String
    if (context.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
        orientation = "portrait"
    } else {
        orientation = "landscape"
    }

    Screen Density

    Device's screen density. (example: 3.000)

    12345678910111213141516171819202122232425
    import android.util.DisplayMetrics
    import android.view.Display
    import android.view.WindowManager
    import android.content.Context
    
    val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        val realDisplayMetrics = DisplayMetrics()
        windowManager.defaultDisplay.getRealMetrics(realDisplayMetrics)
        val width = realDisplayMetrics.widthPixels
        val height = realDisplayMetrics.heightPixels
        val dpi = realDisplayMetrics.densityDpi
    } else {
        val displayMetrics = DisplayMetrics()
        windowManager.defaultDisplay.getMetrics(displayMetrics)
        try {
            val width = Display::class.java
                    .getMethod("getRawWidth")
                    .invoke(windowManager.defaultDisplay) as Int
            val height = Display::class.java
                    .getMethod("getRawHeight")
                    .invoke(windowManager.defaultDisplay) as Int
            val dpi = displayMetrics.densityDpi
        } catch (_: Exception) { }
    }

    Screen Width

    Device's actual width. (example: 375.0)

    12345678910111213141516171819202122232425
    import android.util.DisplayMetrics
    import android.view.Display
    import android.view.WindowManager
    import android.content.Context
    
    val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        val realDisplayMetrics = DisplayMetrics()
        windowManager.defaultDisplay.getRealMetrics(realDisplayMetrics)
        val width = realDisplayMetrics.widthPixels
        val height = realDisplayMetrics.heightPixels
        val dpi = realDisplayMetrics.densityDpi
    } else {
        val displayMetrics = DisplayMetrics()
        windowManager.defaultDisplay.getMetrics(displayMetrics)
        try {
            val width = Display::class.java
                    .getMethod("getRawWidth")
                    .invoke(windowManager.defaultDisplay) as Int
            val height = Display::class.java
                    .getMethod("getRawHeight")
                    .invoke(windowManager.defaultDisplay) as Int
            val dpi = displayMetrics.densityDpi
        } catch (_: Exception) { }
    }

    Screen Height

    Device's actual height. (example: 667.0)

    12345678910111213141516171819202122232425
    import android.util.DisplayMetrics
    import android.view.Display
    import android.view.WindowManager
    import android.content.Context
    
    val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        val realDisplayMetrics = DisplayMetrics()
        windowManager.defaultDisplay.getRealMetrics(realDisplayMetrics)
        val width = realDisplayMetrics.widthPixels
        val height = realDisplayMetrics.heightPixels
        val dpi = realDisplayMetrics.densityDpi
    } else {
        val displayMetrics = DisplayMetrics()
        windowManager.defaultDisplay.getMetrics(displayMetrics)
        try {
            val width = Display::class.java
                    .getMethod("getRawWidth")
                    .invoke(windowManager.defaultDisplay) as Int
            val height = Display::class.java
                    .getMethod("getRawHeight")
                    .invoke(windowManager.defaultDisplay) as Int
            val dpi = displayMetrics.densityDpi
        } catch (_: Exception) { }
    }

    Longitude

    Longitude of device's LastKnownLocation.

    12345678910111213141516
    import android.location.Location
    import android.location.LocationManager
    
    val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
    val gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
    val netLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
    val bestLocation: Location = when {
        (gpsLocation != null) and (netLocation != null) -> if (gpsLocation.accuracy < netLocation.accuracy) { gpsLocation } else { netLocation }
        (gpsLocation != null) -> gpsLocation
        else -> netLocation
    } ?: return null
    
    val latitude = bestLocation?.latitude
    val longitude = bestLocation?.longitude
    val altitude = bestLocation?.altitude
    val speed = bestLocation?.speed

    Latitude

    Latitude of device's LastKnownLocation.

    12345678910111213141516
    import android.location.Location
    import android.location.LocationManager
    
    val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
    val gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
    val netLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
    val bestLocation: Location = when {
        (gpsLocation != null) and (netLocation != null) -> if (gpsLocation.accuracy < netLocation.accuracy) { gpsLocation } else { netLocation }
        (gpsLocation != null) -> gpsLocation
        else -> netLocation
    } ?: return null
    
    val latitude = bestLocation?.latitude
    val longitude = bestLocation?.longitude
    val altitude = bestLocation?.altitude
    val speed = bestLocation?.speed

    Altitude

    Altitude of device's LastKnownLocation.

    12345678910111213141516
    import android.location.Location
    import android.location.LocationManager
    
    val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
    val gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
    val netLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
    val bestLocation: Location = when {
        (gpsLocation != null) and (netLocation != null) -> if (gpsLocation.accuracy < netLocation.accuracy) { gpsLocation } else { netLocation }
        (gpsLocation != null) -> gpsLocation
        else -> netLocation
    } ?: return null
    
    val latitude = bestLocation?.latitude
    val longitude = bestLocation?.longitude
    val altitude = bestLocation?.altitude
    val speed = bestLocation?.speed

    Speed

    Speed of device's LastKnownLocation.

    12345678910111213141516
    import android.location.Location
    import android.location.LocationManager
    
    val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
    val gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
    val netLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
    val bestLocation: Location = when {
        (gpsLocation != null) and (netLocation != null) -> if (gpsLocation.accuracy < netLocation.accuracy) { gpsLocation } else { netLocation }
        (gpsLocation != null) -> gpsLocation
        else -> netLocation
    } ?: return null
    
    val latitude = bestLocation?.latitude
    val longitude = bestLocation?.longitude
    val altitude = bestLocation?.altitude
    val speed = bestLocation?.speed

    Network Carrier

    Device network carrier information.

    1234
    import android.telephony.TelephonyManager
    
    val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
    val carrier = telephonyManager.networkOperatorName

    Bluetooth Status

    Device bluetooth status. (example: true)

    1234
    import android.bluetooth.BluetoothAdapter
    
    val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
    val enabled = bluetoothAdapter.isEnabled

    Cellular Status

    Device mobile data status. (example: true)

    1234567891011121314
    import android.net.ConnectivityManager
    import android.net.NetworkCapabilities
    import android.content.Context
    
    val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
    
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        val activeNetwork = connectivityManager.activeNetwork
        val capabilities = connectivityManager.getNetworkCapabilities(activeNetwork)
        val cellularEnabled = capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)
    } else {
        val networkInfo = connectivityManager.activeNetworkInfo
        val cellularEnabled = (networkInfo.type == ConnectivityManager.TYPE_MOBILE)
    }

    Wifi Status

    Device wifi status. (example: true)

    1234567891011121314
    import android.net.ConnectivityManager
    import android.net.NetworkCapabilities
    import android.content.Context
    
    val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
    
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        val activeNetwork = connectivityManager.activeNetwork
        val capabilities = connectivityManager.getNetworkCapabilities(activeNetwork)
        val wifiEnabled = capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
    } else {
        val networkInfo = connectivityManager.activeNetworkInfo
        val wifiEnabled = (networkInfo.type == ConnectivityManager.TYPE_WIFI)
    }

    Package Name

    Application package name. (example: co.ab180.ablog)

    12345678910
    import android.content.pm.PackageManager
    import android.content.Context
    
    var packageName = ""
    try {
        val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
        packageName = packageInfo.packageName
    } catch (e: PackageManager.NameNotFoundException) {
    
    }

    Version

    Application version name. (example: 1.0.0)

    12345678910
    import android.content.pm.PackageManager
    import android.content.Context
    
    var versionName = ""
    try {
        val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
        versionName = packageInfo.versionName
    } catch (e: PackageManager.NameNotFoundException) {
    
    }

    Event Timestamp

    Timestamp(milliseconds) of when the event was sent. (example: 1581043739682)

    1
    System.currentTimeMillis()

    このページは役に立ちましたか?

    ご質問やご提案はありますか?