feat:"调试穿山甲广告可不影响程序执行成都"
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- 网络与广告相关权限 -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<!-- 定位(可选) -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<!-- 访问图片(Android 13+ 使用 READ_MEDIA_IMAGES,兼容旧版使用 READ_EXTERNAL_STORAGE) -->
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<application
|
||||
android:label="my_app"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:replace="android:label">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
|
||||
@@ -1,5 +1,81 @@
|
||||
package com.example.my_app
|
||||
|
||||
import android.content.Context
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import com.bytedance.sdk.openadsdk.TTAdConfig
|
||||
import com.bytedance.sdk.openadsdk.TTAdSdk
|
||||
|
||||
class MainActivity : FlutterActivity()
|
||||
class MainActivity : FlutterActivity() {
|
||||
|
||||
private val pangleChannelName = "pangle_mediation"
|
||||
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, pangleChannelName)
|
||||
.setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"init" -> {
|
||||
initMediationAdSdk(this)
|
||||
result.success(null)
|
||||
}
|
||||
"initWithConfig" -> {
|
||||
val args = call.arguments as? Map<*, *>
|
||||
val appId = args?.get("appId") as? String ?: ""
|
||||
val privacy = args?.get("privacy") as? Map<*, *>
|
||||
initMediationAdSdk(this, appId, privacy)
|
||||
result.success(null)
|
||||
}
|
||||
"showSplash" -> {
|
||||
val args = call.arguments as? Map<*, *>
|
||||
val codeId = args?.get("codeId") as? String ?: ""
|
||||
SplashAdActivity.start(this, codeId)
|
||||
result.success(null)
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initMediationAdSdk(context: Context, appIdOverride: String? = null, privacy: Map<*, *>? = null) {
|
||||
TTAdSdk.init(context, buildConfig(context, appIdOverride, privacy))
|
||||
TTAdSdk.start(object : TTAdSdk.Callback {
|
||||
override fun success() {
|
||||
}
|
||||
|
||||
override fun fail(code: Int, msg: String?) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun buildConfig(context: Context, appIdOverride: String? = null, privacy: Map<*, *>? = null): TTAdConfig {
|
||||
val appName = context.applicationInfo.loadLabel(context.packageManager).toString()
|
||||
val customController = object : com.bytedance.sdk.openadsdk.TTCustomController() {
|
||||
override fun isCanUseLocation(): Boolean {
|
||||
return privacy?.get("canUseLocation") as? Boolean ?: false
|
||||
}
|
||||
|
||||
override fun isCanUsePhoneState(): Boolean {
|
||||
return privacy?.get("canUsePhoneState") as? Boolean ?: false
|
||||
}
|
||||
|
||||
override fun isCanUseWifiState(): Boolean {
|
||||
return privacy?.get("canUseWifiState") as? Boolean ?: true
|
||||
}
|
||||
|
||||
override fun isCanUseWriteExternal(): Boolean {
|
||||
return privacy?.get("canUseWriteExternal") as? Boolean ?: false
|
||||
}
|
||||
}
|
||||
return TTAdConfig.Builder()
|
||||
.appId(appIdOverride ?: "")
|
||||
.appName(appName)
|
||||
.useMediation(true)
|
||||
.debug(true)
|
||||
.supportMultiProcess(false)
|
||||
.customController(customController)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user