1. 升级依赖版本
2. 解决运行项目警告日志问题 3. 优化代码
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("kotlin-android")
|
||||
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
|
||||
// The Flutter Gradle Plugin must be applied after the Android Gradle plugin.
|
||||
id("dev.flutter.flutter-gradle-plugin")
|
||||
}
|
||||
|
||||
@@ -17,10 +16,6 @@ android {
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId = appPackageName
|
||||
// You can update the following values to match your application needs.
|
||||
@@ -40,6 +35,12 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
val cameraxVersion = "1.4.1"
|
||||
implementation("androidx.camera:camera-core:$cameraxVersion")
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.gdfw.fxjk
|
||||
|
||||
object AppConstants {
|
||||
const val PACKAGE_NAME = "com.gdfw.fxjk"
|
||||
const val PLATFORM_INFO_CHANNEL = "$PACKAGE_NAME/platform_info"
|
||||
const val RECORDING_METHOD_CHANNEL = "$PACKAGE_NAME/recording"
|
||||
const val RECORDING_EVENT_CHANNEL = "$PACKAGE_NAME/recording_events"
|
||||
const val RECORDING_ACTION_START = "$PACKAGE_NAME.recording.START"
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package com.gdfw.fxjk
|
||||
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.os.Build
|
||||
import androidx.camera.view.PreviewView
|
||||
import com.gdfw.fxjk.recording.RecordingPlatformHandler
|
||||
import com.gdfw.fxjk.recording.RecordingPreviewFactory
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
class MainActivity : FlutterActivity() {
|
||||
private var platformHandler: RecordingPlatformHandler? = null
|
||||
private var platformInfoChannel: MethodChannel? = null
|
||||
|
||||
var recordingPreviewView: PreviewView? = null
|
||||
private set
|
||||
@@ -22,6 +26,20 @@ class MainActivity : FlutterActivity() {
|
||||
RecordingPreviewFactory(this),
|
||||
)
|
||||
|
||||
platformInfoChannel =
|
||||
MethodChannel(
|
||||
flutterEngine.dartExecutor.binaryMessenger,
|
||||
AppConstants.PLATFORM_INFO_CHANNEL,
|
||||
).also { channel ->
|
||||
channel.setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"packageInfo" -> result.success(packageInfoMap())
|
||||
"deviceInfo" -> result.success(deviceInfoMap())
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
platformHandler =
|
||||
RecordingPlatformHandler(
|
||||
this,
|
||||
@@ -40,8 +58,63 @@ class MainActivity : FlutterActivity() {
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
platformInfoChannel?.setMethodCallHandler(null)
|
||||
platformInfoChannel = null
|
||||
platformHandler?.dispose()
|
||||
platformHandler = null
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun packageInfoMap(): Map<String, String> {
|
||||
val packageInfo =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
packageManager.getPackageInfo(
|
||||
packageName,
|
||||
android.content.pm.PackageManager.PackageInfoFlags.of(0),
|
||||
)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
packageManager.getPackageInfo(packageName, 0)
|
||||
}
|
||||
|
||||
val appName =
|
||||
applicationInfo.loadLabel(packageManager)?.toString().orEmpty()
|
||||
val versionCode =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
packageInfo.longVersionCode.toString()
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
packageInfo.versionCode.toString()
|
||||
}
|
||||
|
||||
return mapOf(
|
||||
"appName" to appName,
|
||||
"packageName" to packageName,
|
||||
"version" to packageInfo.versionName.orEmpty(),
|
||||
"buildNumber" to versionCode,
|
||||
)
|
||||
}
|
||||
|
||||
private fun deviceInfoMap(): Map<String, Any> {
|
||||
val flags = applicationInfo.flags
|
||||
val isEmulator =
|
||||
Build.FINGERPRINT.startsWith("generic") ||
|
||||
Build.FINGERPRINT.startsWith("unknown") ||
|
||||
Build.MODEL.contains("google_sdk") ||
|
||||
Build.MODEL.contains("Emulator") ||
|
||||
Build.MODEL.contains("Android SDK built for x86") ||
|
||||
Build.MANUFACTURER.contains("Genymotion") ||
|
||||
Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic") ||
|
||||
Build.PRODUCT == "google_sdk" ||
|
||||
flags and ApplicationInfo.FLAG_DEBUGGABLE != 0 &&
|
||||
Build.HARDWARE.contains("ranchu")
|
||||
|
||||
return mapOf(
|
||||
"platform" to "android",
|
||||
"brand" to Build.BRAND,
|
||||
"model" to Build.MODEL,
|
||||
"systemVersion" to Build.VERSION.RELEASE,
|
||||
"isPhysicalDevice" to !isEmulator,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user