feat:参照研听的基础工程
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="dev.fluttercommunity.android_oaid">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package dev.fluttercommunity.android_oaid
|
||||
|
||||
import android.content.ContentResolver
|
||||
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
||||
import io.flutter.plugin.common.MethodChannel.Result
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
|
||||
import com.umeng.commonsdk.UMConfigure
|
||||
|
||||
/** AndroidOaidPlugin */
|
||||
class AndroidOaidPlugin : FlutterPlugin, MethodCallHandler {
|
||||
|
||||
private lateinit var channel: MethodChannel
|
||||
|
||||
private lateinit var contentResolver: ContentResolver
|
||||
|
||||
private lateinit var context: Context
|
||||
|
||||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||
contentResolver = flutterPluginBinding.applicationContext.contentResolver
|
||||
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "android_oaid")
|
||||
channel.setMethodCallHandler(this)
|
||||
context = flutterPluginBinding.getApplicationContext()
|
||||
}
|
||||
|
||||
override fun onMethodCall(call: MethodCall, result: Result) {
|
||||
when (call.method) {
|
||||
"getOaid" -> {
|
||||
try {
|
||||
UMConfigure.getOaid(context) { p0 ->
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
if (p0 != null) {
|
||||
result.success(p0)
|
||||
} else {
|
||||
result.success("")
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
result.success("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
channel.setMethodCallHandler(null)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user