接入广告.
This commit is contained in:
parent
8808620fe1
commit
2333d793f2
|
|
@ -48,7 +48,7 @@ android {
|
|||
applicationId = "com.huanmeng.talk"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||
minSdk = flutter.minSdkVersion
|
||||
minSdk = 21
|
||||
targetSdk = flutter.targetSdkVersion
|
||||
versionCode = flutterVersionCode.toInteger()
|
||||
versionName = flutterVersionName
|
||||
|
|
@ -83,6 +83,9 @@ dependencies {
|
|||
// api 'org.greenrobot:eventbus:3.3.1'
|
||||
//配置eventbus
|
||||
implementation 'org.simple:androideventbus:1.0.5.1'
|
||||
|
||||
//融合基础包,必须引入
|
||||
// implementation "com.pangle.cn:mediation-sdk:6.5.0.2"
|
||||
}
|
||||
|
||||
flutter {
|
||||
|
|
|
|||
BIN
android/app/libs/open_ad_sdk.aar
Normal file
BIN
android/app/libs/open_ad_sdk.aar
Normal file
Binary file not shown.
|
|
@ -2,9 +2,10 @@
|
|||
package="com.huanmeng.talk">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:name="${applicationName}"
|
||||
android:name=".App"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="妙语星河">
|
||||
<activity
|
||||
|
|
@ -50,6 +51,22 @@
|
|||
android:exported="true"
|
||||
android:targetActivity=".wxapi.WXPayEntryActivity" />
|
||||
|
||||
<!-- 穿山甲 start================== -->
|
||||
<provider
|
||||
android:name="com.bytedance.sdk.openadsdk.TTFileProvider"
|
||||
android:authorities="${applicationId}.TTFileProvider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/pangle_file_paths" />
|
||||
</provider>
|
||||
|
||||
<provider
|
||||
android:name="com.bytedance.sdk.openadsdk.multipro.TTMultiProvider"
|
||||
android:authorities="${applicationId}.TTMultiProvider"
|
||||
android:exported="false" />
|
||||
<!-- 穿山甲 end================== -->
|
||||
|
||||
</application>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
|
|
|
|||
37
android/app/src/main/java/com/huanmeng/talk/App.java
Normal file
37
android/app/src/main/java/com/huanmeng/talk/App.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package com.huanmeng.talk;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.bytedance.sdk.openadsdk.TTAdConfig;
|
||||
import com.bytedance.sdk.openadsdk.TTAdSdk;
|
||||
|
||||
import io.flutter.app.FlutterApplication;
|
||||
|
||||
public class App extends FlutterApplication {
|
||||
|
||||
|
||||
public static App instance;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
instance = this;
|
||||
//初始化广告SDK
|
||||
TTAdSdk.init(instance, buildConfig(instance));
|
||||
}
|
||||
|
||||
private static TTAdConfig buildConfig(Context context) {
|
||||
return new TTAdConfig.Builder()
|
||||
.appId("5639401")//应用ID
|
||||
.useMediation(true)//开启聚合功能,默认false
|
||||
.supportMultiProcess(true)//开启多进程
|
||||
.build();
|
||||
}
|
||||
|
||||
public static App getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -12,6 +12,12 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.alipay.sdk.app.PayTask;
|
||||
import com.bytedance.sdk.openadsdk.AdSlot;
|
||||
import com.bytedance.sdk.openadsdk.TTAdConstant;
|
||||
import com.bytedance.sdk.openadsdk.TTAdNative;
|
||||
import com.bytedance.sdk.openadsdk.TTAdSdk;
|
||||
import com.bytedance.sdk.openadsdk.TTRewardVideoAd;
|
||||
import com.bytedance.sdk.openadsdk.mediation.ad.MediationAdSlot;
|
||||
import com.tencent.mm.opensdk.modelpay.PayReq;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
||||
|
|
@ -31,6 +37,7 @@ import io.flutter.plugin.common.MethodChannel;
|
|||
import io.flutter.plugin.common.StandardMethodCodec;
|
||||
|
||||
public class MainActivity extends FlutterActivity {
|
||||
private final String TAG = "MainActivity";
|
||||
private static final String CHANNEL = "samples.flutter.dev/battery";
|
||||
private MethodChannel nativeChannel;
|
||||
|
||||
|
|
@ -38,12 +45,14 @@ public class MainActivity extends FlutterActivity {
|
|||
|
||||
private final String APP_ID = "wxa4009a51b6438a06";
|
||||
|
||||
private TTRewardVideoAd mTTRewardVideoAd;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EventBus.getDefault().register(this);
|
||||
Log.d("TAG", "onCreate: EventBus");
|
||||
Log.d(TAG, "onCreate: EventBus");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -54,6 +63,9 @@ public class MainActivity extends FlutterActivity {
|
|||
@Override
|
||||
protected void onDestroy() {
|
||||
EventBus.getDefault().unregister(this);
|
||||
if (mTTRewardVideoAd != null && mTTRewardVideoAd.getMediationManager() != null) {
|
||||
mTTRewardVideoAd.getMediationManager().destroy();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
|
@ -89,15 +101,12 @@ public class MainActivity extends FlutterActivity {
|
|||
@Override
|
||||
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
|
||||
switch (call.method) {
|
||||
case "test":
|
||||
Log.d("TAG", "onMethodCall: 66666666666");
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("test", "ADSuccess");
|
||||
nativeChannel.invokeMethod("test", map);
|
||||
case "initData"://用户同意协议
|
||||
initData();
|
||||
break;
|
||||
case "WxPay"://微信支付
|
||||
String orderInfoWx = call.argument("orderInfoWx");
|
||||
Log.d("TAG", "onMethodCall: orderInfoWx===" + orderInfoWx);
|
||||
Log.d(TAG, "onMethodCall: orderInfoWx===" + orderInfoWx);
|
||||
|
||||
WxPay(orderInfoWx);
|
||||
|
||||
|
|
@ -114,7 +123,7 @@ public class MainActivity extends FlutterActivity {
|
|||
break;
|
||||
|
||||
case "playAd"://看广告
|
||||
|
||||
loadAd();
|
||||
break;
|
||||
case "test1":
|
||||
Log.d("TAG1", "onMethodCall: 66666666666");
|
||||
|
|
@ -124,6 +133,118 @@ public class MainActivity extends FlutterActivity {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
private void initData() {
|
||||
|
||||
|
||||
//初始化广告
|
||||
TTAdSdk.start(new TTAdSdk.Callback() {
|
||||
@Override
|
||||
public void success() {
|
||||
Log.i("TTAdSdk", "success: " + TTAdSdk.isSdkReady());
|
||||
// initAd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(int code, String msg) {
|
||||
Log.i("TTAdSdk", "fail: code = " + code + " msg = " + msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//加载广告
|
||||
private void loadAd() {
|
||||
TTAdNative adNativeLoader = TTAdSdk.getAdManager().createAdNative(MainActivity.this);
|
||||
AdSlot adslot = new AdSlot.Builder()
|
||||
.setCodeId("962545848")
|
||||
.setOrientation(TTAdConstant.VERTICAL)//横竖屏设置
|
||||
.setMediationAdSlot(new MediationAdSlot
|
||||
.Builder()
|
||||
.build())
|
||||
.build();
|
||||
//广告加载监听
|
||||
adNativeLoader.loadRewardVideoAd(adslot, new TTAdNative.RewardVideoAdListener() {
|
||||
@Override
|
||||
public void onError(int i, String s) {
|
||||
Log.d(TAG, "onError: i==" + i);
|
||||
Log.d(TAG, "onError: s==" + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRewardVideoAdLoad(TTRewardVideoAd ttRewardVideoAd) {
|
||||
mTTRewardVideoAd = ttRewardVideoAd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRewardVideoCached() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRewardVideoCached(TTRewardVideoAd ttRewardVideoAd) {
|
||||
Log.d(TAG, "onRewardVideoCached: ");
|
||||
mTTRewardVideoAd = ttRewardVideoAd;
|
||||
//可在该回调后进行广告展示 广告已准备好
|
||||
playAd();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//看广告
|
||||
private void playAd() {
|
||||
//播放
|
||||
mTTRewardVideoAd.showRewardVideoAd(this);
|
||||
mTTRewardVideoAd.setRewardAdInteractionListener(new TTRewardVideoAd.RewardAdInteractionListener() {
|
||||
@Override
|
||||
public void onAdShow() {
|
||||
Log.d("TAG", "onAdShow: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdVideoBarClick() {
|
||||
Log.d(TAG, "onAdVideoBarClick: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdClose() {
|
||||
Log.d(TAG, "onAdClose: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoComplete() {
|
||||
Log.d(TAG, "onVideoComplete: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoError() {
|
||||
Log.d(TAG, "onVideoError: ");
|
||||
}
|
||||
|
||||
@Override //已废弃,请使用onRewardArrived方法
|
||||
public void onRewardVerify(boolean b, int i, String s, int i1, String s1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRewardArrived(boolean isRewardValid, int rewardType, Bundle extraInfo) {//奖励是否发放请依据isRewardValid
|
||||
Log.d("TAG", "onRewardArrived: isRewardValid==" + isRewardValid);
|
||||
Log.d("TAG", "onRewardArrived: rewardType==" + rewardType);
|
||||
Log.d("TAG", "onRewardArrived: extraInfo==" + extraInfo);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSkippedVideo() {
|
||||
Log.d(TAG, "onSkippedVideo: ");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付宝支付回调
|
||||
*/
|
||||
@SuppressLint("HandlerLeak")
|
||||
private Handler mHandler = new Handler() {
|
||||
@SuppressWarnings("unused")
|
||||
|
|
@ -166,6 +287,11 @@ public class MainActivity extends FlutterActivity {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 微信支付
|
||||
*
|
||||
* @param orderInfo 支付信息
|
||||
*/
|
||||
private void WxPay(String orderInfo) {
|
||||
|
||||
IWXAPI api = WXAPIFactory.createWXAPI(MainActivity.this, APP_ID);
|
||||
|
|
|
|||
8
android/app/src/main/res/xml/pangle_file_paths.xml
Normal file
8
android/app/src/main/res/xml/pangle_file_paths.xml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<external-path name="tt_external_root" path="." />
|
||||
<external-path name="tt_external_download" path="Download" />
|
||||
<external-files-path name="tt_external_files_download" path="Download" />
|
||||
<files-path name="tt_internal_file_download" path="Download" />
|
||||
<cache-path name="tt_internal_cache_download" path="Download" />
|
||||
</paths>
|
||||
|
|
@ -4,6 +4,7 @@ import 'dart:io';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:talk/network/NetworkConfig.dart';
|
||||
import 'package:talk/tools/creat/create_page.dart';
|
||||
import 'package:talk/tools/home_page.dart';
|
||||
import 'package:talk/tools/login/login_page.dart';
|
||||
|
|
@ -52,9 +53,6 @@ class _ChatAppState extends State<ChatApp> {
|
|||
// 注册方法,等待被原生通过invokeMethod唤起
|
||||
Future<dynamic> nativeCallHandler(MethodCall methodCall) async {
|
||||
switch (methodCall.method) {
|
||||
case "test":
|
||||
print("object77777");
|
||||
break;
|
||||
|
||||
case "AlipaySuccess": //支付宝支付完成
|
||||
// EasyLoading.showToast("支付成功");
|
||||
|
|
|
|||
|
|
@ -560,11 +560,6 @@ class _HomeChatPageState extends State<HomeChatPage> with AutomaticKeepAliveClie
|
|||
}
|
||||
isMore = !isMore;
|
||||
setState(() {});
|
||||
|
||||
// Map<String, dynamic> map = {
|
||||
// "test": "test",
|
||||
// };
|
||||
// invokeNativeMethod("test", map);
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(left: 14),
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
timer.cancel();
|
||||
setState(() {
|
||||
_isCountingDown = false;
|
||||
_timeLeft = 5;
|
||||
_timeLeft = 60;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
|
|||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:talk/network/NetworkConfig.dart';
|
||||
|
||||
import '../common/Global.dart';
|
||||
import '../common/func.dart';
|
||||
import '../dialog/agreement_dialog.dart';
|
||||
import 'login/login_model.dart';
|
||||
|
|
@ -60,6 +61,10 @@ class _StartPageState extends State<StartPage> {
|
|||
} else {
|
||||
Navigator.pushReplacementNamed(context, "/HomePage");
|
||||
}
|
||||
Map<String, dynamic> map = {
|
||||
"initData": "initData",
|
||||
};
|
||||
invokeNativeMethod("initData", map);
|
||||
setIsFirst();
|
||||
}
|
||||
|
||||
|
|
@ -99,4 +104,12 @@ class _StartPageState extends State<StartPage> {
|
|||
image: const AssetImage('assets/images/img_start.png'),
|
||||
);
|
||||
}
|
||||
|
||||
// 获取原生的值
|
||||
invokeNativeMethod(String method, Map<String, dynamic> map) async {
|
||||
dynamic args;
|
||||
try {
|
||||
args = await Global.method.invokeMethod(method, map);
|
||||
} on PlatformException catch (e) {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user