package com.freaccess.hub

import android.os.Bundle
import android.provider.Settings
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity: FlutterFragmentActivity() {
  private val CHANNEL = "com.freaccess.hub/getAndroidId"
  override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
    super.configureFlutterEngine(flutterEngine)
    MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
      if (call.method == "getAndroidId") {
        val androidId = getAndroidId()
        if (androidId != null) {
          result.success(androidId)
        } else {
          result.error("UNAVAILABLE", "Android ID not available.", null)
        }
      } else {
        result.notImplemented()
      }
    }
  }
  private fun getAndroidId(): String? {
    return Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
  }
}