|
|
|
|
@ -1,6 +1,14 @@
|
|
|
|
|
package com.ejada.hmg.utils
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.content.Intent.getIntent
|
|
|
|
|
import android.net.Uri
|
|
|
|
|
import android.os.Build
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.provider.Settings
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import androidx.core.app.ActivityCompat.startActivityForResult
|
|
|
|
|
import android.net.wifi.WifiManager
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import com.ejada.hmg.MainActivity
|
|
|
|
|
@ -24,6 +32,9 @@ class PlatformBridge(private var flutterEngine: FlutterEngine, private var mainA
|
|
|
|
|
private const val ENABLE_WIFI_IF_NOT = "enableWifiIfNot"
|
|
|
|
|
private const val REGISTER_HMG_GEOFENCES = "registerHmgGeofences"
|
|
|
|
|
private const val UN_REGISTER_HMG_GEOFENCES = "unRegisterHmgGeofences"
|
|
|
|
|
private const val IS_DRAW_OVER_APPS_PERMISSION_ALLOWED = "isDrawOverAppsPermissionAllowed"
|
|
|
|
|
private const val ASK_DRAW_OVER_APPS_PERMISSION = "askDrawOverAppsPermission"
|
|
|
|
|
private const val GET_INTENT = "getIntent"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun create() {
|
|
|
|
|
@ -43,8 +54,13 @@ class PlatformBridge(private var flutterEngine: FlutterEngine, private var mainA
|
|
|
|
|
registerHmgGeofences(methodCall, result)
|
|
|
|
|
} else if (methodCall.method == UN_REGISTER_HMG_GEOFENCES) {
|
|
|
|
|
unRegisterHmgGeofences(methodCall, result)
|
|
|
|
|
} else if (methodCall.method == IS_DRAW_OVER_APPS_PERMISSION_ALLOWED) {
|
|
|
|
|
isDrawOverAppsPermissionAllowed(methodCall, result)
|
|
|
|
|
} else if (methodCall.method == ASK_DRAW_OVER_APPS_PERMISSION) {
|
|
|
|
|
askDrawOverAppsPermission(methodCall, result)
|
|
|
|
|
} else if (methodCall.method == GET_INTENT) {
|
|
|
|
|
getIntentData(methodCall, result)
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
result.notImplemented()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -123,4 +139,42 @@ class PlatformBridge(private var flutterEngine: FlutterEngine, private var mainA
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun isDrawOverAppsPermissionAllowed(methodCall: MethodCall, result: MethodChannel.Result) {
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
|
if (
|
|
|
|
|
Settings.canDrawOverlays(mainActivity)
|
|
|
|
|
) {
|
|
|
|
|
result.success(true)
|
|
|
|
|
} else {
|
|
|
|
|
result.success(false)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
result.success(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun askDrawOverAppsPermission(methodCall: MethodCall, result: MethodChannel.Result) {
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
|
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)
|
|
|
|
|
val uri = Uri.parse("package:" + mainActivity.getPackageName())
|
|
|
|
|
intent.setData(uri)
|
|
|
|
|
startActivityForResult(mainActivity, intent, 102, null)
|
|
|
|
|
result.success(true)
|
|
|
|
|
} else {
|
|
|
|
|
result.success(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun getIntentData(methodCall: MethodCall, result: MethodChannel.Result) {
|
|
|
|
|
|
|
|
|
|
val bundle: Bundle? = getIntent("").extras
|
|
|
|
|
if (bundle != null) {
|
|
|
|
|
val message = bundle.getString("notification") // 1
|
|
|
|
|
System.out.println("BundleExtra:" + message)
|
|
|
|
|
Toast.makeText(this.mainActivity, message + "", Toast.LENGTH_SHORT).show()
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(this.mainActivity, "Bundle Null", Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
result.success(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|