update tencent ad

This commit is contained in:
mwang 2019-06-24 22:34:53 +08:00
parent 95546f9b90
commit a871acb164
12 changed files with 215 additions and 427 deletions

View File

@ -14,7 +14,7 @@ android {
buildToolsVersion "28.0.3"
defaultConfig {
// applicationId "com.qq.e.union.demo"
applicationId "com.novelbook.android"
applicationId "com.zhushou.yueshu"
minSdkVersion 19 //target 19 Android 4.4 4.1%
targetSdkVersion 28
versionCode 6
@ -79,37 +79,21 @@ android {
//
/* productFlavors {
// googleplay {}
huawei {
yingyonghui {
applicationId "com.zhushou.yueshu"
versionName "v1.0"
buildConfigField "String", "MAIN_HOST", '"http://g.xiaoshuofenxiang.com/api/"'
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
}
google {
applicationId "com.zhushou.yueshu"
versionName "v1.0"
buildConfigField "String", "MAIN_HOST", '"http://g.xiaoshuofenxiang.com/api/"'
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
}
ali {
yiwan {
applicationId "com.zhushou.yueshu"
versionName "v1.0"
buildConfigField "String", "MAIN_HOST", '"http://g.xiaoshuofenxiang.com/api/"'
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
}
qq {
applicationId "com.zhushou.yueshu"
versionName "v1.0"
buildConfigField "String", "MAIN_HOST", '"http://g.xiaoshuofenxiang.com/api/"'
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
//buildConfigField "String", "API_HOST", '""'
}
xiaomi {
haote {
applicationId "com.zhushou.yueshu"
versionName "v1.0"
buildConfigField "String", "MAIN_HOST", '"http://g.xiaoshuofenxiang.com/api/"'
@ -117,35 +101,6 @@ android {
}
kuan {
applicationId "com.zhushou.yueshu"
versionName "v1.0"
buildConfigField "String", "MAIN_HOST", '"http://g.xiaoshuofenxiang.com/api/"'
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
}
m360 {
applicationId "com.zhushou.yueshu"
versionName "v1.0"
buildConfigField "String", "MAIN_HOST", '"http://g.xiaoshuofenxiang.com/api/"'
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
}
baidu {
applicationId "com.zhushou.yueshu"
versionName "v1.0"
buildConfigField "String", "MAIN_HOST", '"http://g.xiaoshuofenxiang.com/api/"'
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
}
m91 {
applicationId "com.zhushou.yueshu"
versionName "v1.0"
buildConfigField "String", "MAIN_HOST", '"http://g.xiaoshuofenxiang.com/api/"'
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
}
anzhi {
applicationId "com.zhushou.yueshu"
versionName "v1.0"
@ -153,27 +108,14 @@ android {
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
}
wzzw {
applicationId "com.novelbook.android.wzzw"
versionName "v-wzzw-5.0"
buildConfigField "String", "MAIN_HOST", '"http://chwzzw.xiaoshuofenxiang.com/api/"'
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/wzzw.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
// buildConfigField "String", "API_HOST", '""'
}
bo {
applicationId "com.novelbook.android.bo"
versionName "v-bo-5.0"
buildConfigField "String", "MAIN_HOST", '"http://chbo.xiaoshuofenxiang.com/api/"'
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/bo.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
// buildConfigField "String", "API_HOST", '""'
}
g {
applicationId "com.novelbook.android.g"
versionName "v-g-5.0"
buildConfigField "String", "MAIN_HOST", '"http://chg.xiaoshuofenxiang.com/api/"'
google {
applicationId "com.zhushou.yueshu"
versionName "v1.0"
buildConfigField "String", "MAIN_HOST", '"http://g.xiaoshuofenxiang.com/api/"'
buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/g.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"'
// buildConfigField "String", "API_HOST", '""'
}
//
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
@ -247,6 +189,6 @@ dependencies {
implementation 'q.rorbin:VerticalTabLayout:1.2.5'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16'
implementation(name: 'open_ad_sdk', ext: 'aar')
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.6'
// implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.6'
implementation 'com.google.android.gms:play-services-ads:17.2.1'
}

View File

@ -115,14 +115,12 @@
android:exported="false" />
<!-- qq ad -->
<!-- chuanshanjia ad -->
<activity
<!-- <activity
android:name=".AD.qq.SplashActivity"
android:configChanges="keyboard|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/Theme.Splash">
</activity>
</activity>-->
<service
android:name="com.qq.e.comm.DownloadService"

View File

@ -36,6 +36,7 @@ import com.novelbook.android.AD.toutiao.WeakHandler;
import com.novelbook.android.Main2Activity;
import com.novelbook.android.R;
import com.novelbook.android.utils.CommonUtil;
import com.novelbook.android.utils.Constants;
import com.qq.e.ads.splash.SplashAD;
import com.qq.e.ads.splash.SplashADListener;
@ -381,27 +382,41 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler, Sp
lackedPermission.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (!(checkSelfPermission(Manifest.permission.REQUEST_INSTALL_PACKAGES) == PackageManager.PERMISSION_GRANTED)) {
lackedPermission.add(Manifest.permission.REQUEST_INSTALL_PACKAGES);
CommonUtil.checkPermission(this,Manifest.permission.REQUEST_INSTALL_PACKAGES,1024,"更新程序内容需此权限,请允许");
//lackedPermission.add(Manifest.permission.REQUEST_INSTALL_PACKAGES);
}
/*if (!(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
lackedPermission.add(Manifest.permission.ACCESS_FINE_LOCATION);
}*/
for(String s: lackedPermission){
Log.e(TAG, "checkAndRequestPermission: lack permission "+s );
}
// 权限都已经有了那么直接调用SDK
if (lackedPermission.size() == 0) {
fetchSplashAD(this, mSplashContainer, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0);
} else {
// 请求所缺少的权限在onRequestPermissionsResult中再看是否获得权限如果获得权限就可以调用SDK否则不要调用SDK
Log.e(TAG, "checkAndRequestPermission: lack permission to ask user grant permission" );
for(String s: lackedPermission){
Log.e(TAG, "checkAndRequestPermission: lack permission "+s );
}
String[] requestPermissions = new String[lackedPermission.size()];
lackedPermission.toArray(requestPermissions);
Log.d(TAG, String.format("checkAndRequestPermission: lacked permission size %s",requestPermissions.length));
requestPermissions(requestPermissions, 1024);
}
}
private boolean hasAllPermissionsGranted(int[] grantResults) {
for (int grantResult : grantResults) {
Log.e(TAG, "checkAndRequestPermission: grant result "+grantResult );
if (grantResult == PackageManager.PERMISSION_DENIED) {
return false;
// return false;
}
}
return true;
@ -413,6 +428,7 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler, Sp
if (requestCode == 1024 && hasAllPermissionsGranted(grantResults)) {
fetchSplashAD(this, mSplashContainer, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0);
} else {
Log.d(TAG, String.format("checkAndRequestPermission: permision result requestCode %s,",requestCode ));
// 如果用户没有授权那么应该说明意图引导用户去设置里面授权
Toast.makeText(this, "应用缺少必要的权限!请点击\"权限\",打开所需要的权限。", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
@ -486,7 +502,7 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler, Sp
@Override
public void onNoAD(AdError error) {
Log.i(
"AD_DEMO",
TAG,
String.format("LoadSplashADFail, eCode=%d, errorMsg=%s", error.getErrorCode(),
error.getErrorMsg()));
/**
@ -528,7 +544,7 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler, Sp
//----qq ad end <---
void getAdMob(){
MobileAds.initialize(this,"ca-app-pub-3940256099942544~3347511713");
MobileAds.initialize(this,"ca-app-pub-7589200066914535~9227821515");
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdListener(new AdListener() {
@ -572,7 +588,7 @@ public class SplashActivity extends Activity implements WeakHandler.IHandler, Sp
goToMainActivity();
}
});
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.setAdUnitId("ca-app-pub-7589200066914535/7573202335");
mInterstitialAd.loadAd(new AdRequest.Builder().build());

View File

@ -57,6 +57,9 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks,
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if(activity instanceof SplashActivity){
return;
}
if(Constants.AD_SETTING.getSplash2() .getSource() == Constants.AD_MOB) {
getAdMob(activity);
}
@ -75,12 +78,16 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks,
@Override
public void onActivityResumed(Activity activity) {
if(activity instanceof SplashActivity){
return;
}
if (mIsBackground) {
mIsBackground = false;
showSplashAd(activity);
showSplash2Ad(activity);
Log.d(TAG, "从广告页回到前台");
Log.d(TAG, "从广告页回到前台 "+activity);
}
}
@ -126,7 +133,7 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks,
static void showInterAd(Activity activity){
clearPages();
}
static void showSplashAd(Activity activity){
static void showSplash2Ad(Activity activity){
if(canShowAd()) {
lastAd = new Date().getTime();
@ -160,7 +167,7 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks,
return false;
}
long in = new Date().getTime() -lastAd;
int interVal = Constants.AD_SETTING.getSplash2().getInterval4Display()*10;
int interVal = Constants.AD_SETTING.getSplash2().getInterval4Display()*1000;
Log.d(TAG, "canShowAd: interval is, " +in + ", canshow? "+ (in >interVal));
return in >interVal;
}
@ -173,8 +180,10 @@ public class SplashAdManager implements Application.ActivityLifecycleCallbacks,
int pcnt =Constants.AD_SETTING.getSplash2().getPageCount4Display();;
if(pages > pcnt){
Log.d(TAG, String.format("canShowAd: plusPage pages %s, maxpage %s ", pages,pcnt));
clearPages();
showSplashAd(activity);
showSplash2Ad(activity);
}
}

View File

@ -1,292 +0,0 @@
package com.novelbook.android.AD.qq;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.novelbook.android.Main2Activity;
import com.novelbook.android.R;
import com.novelbook.android.utils.Constants;
import com.qq.e.ads.splash.SplashAD;
import com.qq.e.ads.splash.SplashADListener;
import com.qq.e.comm.util.AdError;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.novelbook.android.bean.AdSetting.getAppID;
/**
* 这是demo工程的入口Activity在这里会首次调用广点通的SDK
*
* 在调用SDK之前如果您的App的targetSDKVersion >= 23那么一定要把"READ_PHONE_STATE""WRITE_EXTERNAL_STORAGE""ACCESS_FINE_LOCATION"这几个权限申请到否则SDK将不会工作
*/
public class SplashActivity extends Activity implements SplashADListener {
private SplashAD splashAD;
private ViewGroup container;
private TextView skipView;
//private ImageView splashHolder;
private TextView splashHolder;
private TextView tvTitle;
private static final String SKIP_TEXT = "点击跳过 %d";
public boolean canJump = false;
/**
* 为防止无广告时造成视觉上类似于"闪退"的情况设定无广告时页面跳转根据需要延迟一定时间demo
* 给出的延时逻辑是从拉取广告开始算开屏最少持续多久仅供参考开发者可自定义延时逻辑如果开发者采用demo
* 中给出的延时逻辑也建议开发者考虑自定义minSplashTimeWhenNoAD的值单位ms
**/
private int minSplashTimeWhenNoAD = 2000;
/**
* 记录拉取广告的时间
*/
private long fetchSplashADTime = 0;
private Handler handler = new Handler(Looper.getMainLooper());
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ad_qq_activity_splash );
container = (ViewGroup) this.findViewById(R.id.splash_container);
skipView = (TextView) findViewById(R.id.skip_view);
tvTitle = (TextView) findViewById(R.id.textTile);
splashHolder = (TextView) findViewById(R.id.splash_holder);
tvTitle.setText(R.string.app_name);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
// | View.SYSTEM_UI_FLAG_IMMERSIVE
);
/* boolean needLogo = getIntent().getBooleanExtra("need_logo", true);
needStartDemoList = getIntent().getBooleanExtra("need_start_demo_list", true);
if (!needLogo) {
findViewById(R.id.app_logo).setVisibility(View.GONE);
}*/
// 如果targetSDKVersion >= 23就要申请好权限如果您的App没有适配到Android6.0即targetSDKVersion < 23那么只需要在这里直接调用fetchSplashAD接口
if (Build.VERSION.SDK_INT >= 23) {
checkAndRequestPermission();
} else {
// 如果是Android6.0以下的机器默认在安装时获得了所有权限可以直接调用SDK
fetchSplashAD(this, container, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0);
}
}
private String getPosId() {
return Constants.AD_SETTING.getSplash().getSlotId(Constants.AD_TENCENT_QQ);
}
/**
*
* ----------非常重要----------
*
* Android6.0以上的权限适配简单示例
*
* 如果targetSDKVersion >= 23那么必须要申请到所需要的权限再调用广点通SDK否则广点通SDK不会工作
*
* Demo代码里是一个基本的权限申请示例请开发者根据自己的场景合理地编写这部分代码来实现权限申请
* 注意下面的`checkSelfPermission``requestPermissions`方法都是在Android6.0的SDK中增加的API如果您的App还没有适配到Android6.0以上则不需要调用这些方法直接调用广点通SDK即可
*/
@TargetApi(Build.VERSION_CODES.M)
private void checkAndRequestPermission() {
List<String> lackedPermission = new ArrayList<String>();
if (!(checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)) {
lackedPermission.add(Manifest.permission.READ_PHONE_STATE);
}
if (!(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
lackedPermission.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (!(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
lackedPermission.add(Manifest.permission.ACCESS_FINE_LOCATION);
}
// 权限都已经有了那么直接调用SDK
if (lackedPermission.size() == 0) {
fetchSplashAD(this, container, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0);
} else {
// 请求所缺少的权限在onRequestPermissionsResult中再看是否获得权限如果获得权限就可以调用SDK否则不要调用SDK
String[] requestPermissions = new String[lackedPermission.size()];
lackedPermission.toArray(requestPermissions);
requestPermissions(requestPermissions, 1024);
}
}
private boolean hasAllPermissionsGranted(int[] grantResults) {
for (int grantResult : grantResults) {
if (grantResult == PackageManager.PERMISSION_DENIED) {
return false;
}
}
return true;
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1024 && hasAllPermissionsGranted(grantResults)) {
fetchSplashAD(this, container, skipView, getAppID(Constants.AD_TENCENT_QQ), getPosId(), this, 0);
} else {
// 如果用户没有授权那么应该说明意图引导用户去设置里面授权
Toast.makeText(this, "应用缺少必要的权限!请点击\"权限\",打开所需要的权限。", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
finish();
}
}
/**
* 拉取开屏广告开屏广告的构造方法有3种详细说明请参考开发者文档
*
* @param activity 展示广告的activity
* @param adContainer 展示广告的大容器
* @param skipContainer 自定义的跳过按钮传入该view给SDK后SDK会自动给它绑定点击跳过事件SkipView的样式可以由开发者自由定制其尺寸限制请参考activity_splash.xml或者接入文档中的说明
* @param appId 应用ID
* @param posId 广告位ID
* @param adListener 广告状态监听器
* @param fetchDelay 拉取广告的超时时长取值范围[3000, 5000]设为0表示使用广点通SDK默认的超时时长
*/
private void fetchSplashAD(Activity activity, ViewGroup adContainer, View skipContainer,
String appId, String posId, SplashADListener adListener, int fetchDelay) {
fetchSplashADTime = System.currentTimeMillis();
Map<String, String> tags = new HashMap<>();
tags.put("tag_s1", "value_s1");
tags.put("tag_s2", "value_s2");
splashAD = new SplashAD(activity, adContainer, skipContainer, appId, posId, adListener,
fetchDelay, tags);
// 如果不需要传tag使用如下构造函数
// splashAD = new SplashAD(activity, adContainer, skipContainer, appId, posId, adListener, fetchDelay);
}
@Override
public void onADPresent() {
Log.i("AD_DEMO", "SplashADPresent");
splashHolder.setVisibility(View.INVISIBLE); // 广告展示后一定要把预设的开屏图片隐藏起来
}
@Override
public void onADClicked() {
Log.i("AD_DEMO", "SplashADClicked clickUrl: "
+ (splashAD.getExt() != null ? splashAD.getExt().get("clickUrl") : ""));
}
/**
* 倒计时回调返回广告还将被展示的剩余时间
* 通过这个接口开发者可以自行决定是否显示倒计时提示或者还剩几秒的时候显示倒计时
*
* @param millisUntilFinished 剩余毫秒数
*/
@Override
public void onADTick(long millisUntilFinished) {
Log.i("AD_DEMO", "SplashADTick " + millisUntilFinished + "ms");
skipView.setText(String.format(SKIP_TEXT, Math.round(millisUntilFinished / 1000f)));
}
@Override
public void onADExposure() {
Log.i("AD_DEMO", "SplashADExposure");
}
@Override
public void onADDismissed() {
Log.i("AD_DEMO", "SplashADDismissed");
next();
}
@Override
public void onNoAD(AdError error) {
Log.i(
"AD_DEMO",
String.format("LoadSplashADFail, eCode=%d, errorMsg=%s", error.getErrorCode(),
error.getErrorMsg()));
/**
* 为防止无广告时造成视觉上类似于"闪退"的情况设定无广告时页面跳转根据需要延迟一定时间demo
* 给出的延时逻辑是从拉取广告开始算开屏最少持续多久仅供参考开发者可自定义延时逻辑如果开发者采用demo
* 中给出的延时逻辑也建议开发者考虑自定义minSplashTimeWhenNoAD的值
**/
long alreadyDelayMills = System.currentTimeMillis() - fetchSplashADTime;//从拉广告开始到onNoAD已经消耗了多少时间
long shouldDelayMills = alreadyDelayMills > minSplashTimeWhenNoAD ? 0 : minSplashTimeWhenNoAD
- alreadyDelayMills;//为防止加载广告失败后立刻跳离开屏可能造成的视觉上类似于"闪退"的情况根据设置的minSplashTimeWhenNoAD
// 计算出还需要延时多久
handler.postDelayed(new Runnable() {
@Override
public void run() {
SplashActivity.this.finish();
}
}, shouldDelayMills);
}
/**
* 设置一个变量来控制当前开屏页面是否可以跳转当开屏广告为普链类广告时点击会打开一个广告落地页此时开发者还不能打开自己的App主页当从广告落地页返回以后
* 才可以跳转到开发者自己的App主页当开屏广告是App类广告时只会下载App
*/
private void next() {
if (canJump) {
this.finish();
} else {
canJump = true;
}
}
@Override
protected void onPause() {
super.onPause();
canJump = false;
}
@Override
protected void onResume() {
super.onResume();
if (canJump) {
next();
}
canJump = true;
}
@Override
protected void onDestroy() {
super.onDestroy();
handler.removeCallbacksAndMessages(null);
}
/** 开屏页一定要禁止用户对返回按钮的控制否则将可能导致用户手动退出了App而广告无法正常曝光和计费 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) {
return true;
}
return super.onKeyDown(keyCode, event);
}
}

View File

@ -42,4 +42,6 @@ public class ActivityAnounce extends Activity_base {
public void fillData() {
}
}

View File

@ -7,6 +7,7 @@ import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@ -22,6 +23,8 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
@ -73,6 +76,8 @@ import java.util.concurrent.ConcurrentHashMap;
import com.qq.e.ads.banner.AbstractBannerADListener;
import com.qq.e.ads.banner.BannerView;
import com.qq.e.ads.banner2.UnifiedBannerADListener;
import com.qq.e.ads.banner2.UnifiedBannerView;
import com.qq.e.ads.cfg.VideoOption;
import com.qq.e.ads.nativ.ADSize;
import com.qq.e.ads.nativ.NativeADUnifiedListener;
@ -95,7 +100,7 @@ import static com.novelbook.android.utils.Constants.AD_MOB;
import static com.novelbook.android.utils.Constants.AD_TENCENT_QQ;
import static com.novelbook.android.utils.Constants.AD_TOUTIAO;
public abstract class Activity_base extends AppCompatActivity implements NativeExpressAD.NativeExpressADListener {
public abstract class Activity_base extends AppCompatActivity implements NativeExpressAD.NativeExpressADListener,UnifiedBannerADListener {
private static final int MSG_AD_LOAD =10 ;
private static String TAG ="Activity_base";
@ -453,7 +458,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native
Log.d(TAG, String.format("loadBanner:mLastBannerTime %s ,timepassed %s",mLastBannerTime,(new Date().getTime() - mLastBannerTime)/1000));
return;
}
mLastBannerTime =new Date().getTime();
Log.d(TAG, "loadBanner:mLastBannerTime start new banner request,mBannerContainer.getChildCount(): "+mBannerContainer.getChildCount());
if(Constants.AD_SETTING.getChapterBanner().getSource()== AD_TENCENT_QQ) {
getBanner_qq();
@ -1086,7 +1091,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native
BannerView bv;
/* BannerView bv;
private void getBanner_qq() {
if(this.bv != null){
@ -1098,8 +1103,8 @@ public abstract class Activity_base extends AppCompatActivity implements Native
}
this.bv = new BannerView(this, com.qq.e.ads.banner.ADSize.BANNER,
AdSetting.getAppID(Constants.AD_TENCENT_QQ),
Constants.AD_SETTING.getChapterBanner().getSlotId(Constants.AD_TENCENT_QQ));
"1109247602" *//* AdSetting.getAppID(Constants.AD_TENCENT_QQ)*//*,
"9000263914551986" *//* Constants.AD_SETTING.getChapterBanner().getSlotId(Constants.AD_TENCENT_QQ)*//*);
// 注意如果开发者的banner不是始终展示在屏幕中的话请关闭自动刷新否则将导致曝光率过低
// 并且应该自行处理当banner广告区域出现在屏幕后再手动loadAD
// bv.setRefresh(0);
@ -1107,24 +1112,85 @@ public abstract class Activity_base extends AppCompatActivity implements Native
@Override
public void onNoAD(AdError error) {
Log.i(
"AD_DEMO",
String.format("Banner onNoADeCode = %d, eMsg = %s", error.getErrorCode(),
Log.d(
TAG,
String.format("loadListAdeCode = %d, eMsg = %s", error.getErrorCode(),
error.getErrorMsg()));
}
@Override
public void onADReceiv() {
Log.i("AD_DEMO", "ONBannerReceive");
Log.d(TAG, "loadListAd ONBannerReceive");
}
});
mBannerContainer.addView(bv);
this.bv.loadAD();
mLastBannerTime =new Date().getTime();
}*/
UnifiedBannerView bv;
//banner2.0
private void getBanner_qq() {
if(this.bv != null){
mBannerContainer.removeView(bv);
bv.destroy();
}
String posId =Constants.AD_SETTING.getChapterBanner().getSlotId(Constants.AD_TENCENT_QQ);//"9000263914551986";
Map<String, String> tags = new HashMap<>();
tags.put("tag_b1", "value_b1");
tags.put("tag_b2", "value_b2");
this.bv = new UnifiedBannerView(this, AdSetting.getAppID(Constants.AD_TENCENT_QQ) , posId, this, tags);
this.bv.setRefresh(0);
// 不需要传递tags使用下面构造函数
// this.bv = new UnifiedBannerView(this, Constants.APPID, posId, this);
mBannerContainer.addView(bv, getUnifiedBannerLayoutParams());
bv.loadAD();
mLastBannerTime =new Date().getTime();
// return this.bv;
}
@Override
public void onADReceive() {
Log.d(TAG, "loadListAd UnifiedBannerView ONBannerReceive");
}
@Override
public void onADExposure() {
Log.d(TAG, "loadListAd UnifiedBannerView onADExposure");
}
@Override
public void onADClosed() {
Log.d(TAG, "loadListAd UnifiedBannerView onADClosed");
}
@Override
public void onADClicked() {
Log.d(TAG, "loadListAd UnifiedBannerView onADClicked");
}
@Override
public void onADLeftApplication() {
Log.d(TAG, "loadListAd UnifiedBannerView onADLeftApplication");
}
@Override
public void onADOpenOverlay() {
Log.d(TAG, "loadListAd UnifiedBannerView onADOpenOverlay");
}
@Override
public void onADCloseOverlay() {
Log.d(TAG, "loadListAd onADCloseOverlay");
}
private FrameLayout.LayoutParams getUnifiedBannerLayoutParams() {
Point screenSize = new Point();
getWindowManager().getDefaultDisplay().getSize(screenSize);
return new FrameLayout.LayoutParams(screenSize.x, Math.round(screenSize.x / 6.4F));
}
//原生上图下文1280x720 8020766944969033
private void loadNativeBanner_qq(int adWidth,int adHeight) {
try {
@ -1140,7 +1206,7 @@ public abstract class Activity_base extends AppCompatActivity implements Native
nativeExpressAD = new NativeExpressAD(this, getMyADSize(adWidth, adHeight),
AdSetting.getAppID(Constants.AD_TENCENT_QQ) ,
Constants.AD_SETTING.getChapterContentBanner().getSlotId(Constants.AD_TENCENT_QQ), this); // 这里的Context必须为Activity
/*原生上图下文1280x720*/ Constants.AD_SETTING.getChapterContentBanner().getSlotId(Constants.AD_TENCENT_QQ) , this); // 这里的Context必须为Activity
/* nativeExpressAD.setVideoOption(new VideoOption.Builder()
.setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI) // 设置什么网络环境下可以自动播放视频
.setAutoPlayMuted(true) // 设置自动播放视频时是否静音
@ -1441,5 +1507,12 @@ public abstract class Activity_base extends AppCompatActivity implements Native
hideProgress();
// MobclickAgent.onPause(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (bv != null) {
bv.destroy();
}
}
}

View File

@ -31,8 +31,10 @@ import com.novelbook.android.BuildConfig;
import com.novelbook.android.Main2Activity;
import com.novelbook.android.R;
import com.novelbook.android.db.Chapter;
import com.novelbook.android.db.DownloadTask;
import com.novelbook.android.db.Novel;
import com.novelbook.android.db.SiteRule;
import com.novelbook.android.filechooser.FileChooserActivity;
import com.novelbook.android.netsubscribe.BookSubscribe;
import com.novelbook.android.netutils.HttpMethods;
@ -56,6 +58,7 @@ import org.litepal.LitePal;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import butterknife.BindView;
@ -102,11 +105,23 @@ public class Fragment_Shelf extends BasicFragment {
}
private void loadNovelsOnShelf() {
Log.d(TAG, String.format("db count info: chapters %s,novels %s,downtask %s,siterule %s,maxsize %s",
LitePal.count(Chapter.class), LitePal.count(Novel.class),LitePal.count(DownloadTask.class),LitePal.count(SiteRule.class)
,Fileutil.formatFileSize( LitePal.getDatabase().getMaximumSize())
));
try{
throw new Exception("show trace");
}catch (Exception e){
Log.e(TAG, "loadNovelsOnShelf: ",e);
}
bookLists = Novel.getNovelsOnShelf();
noveIds = "";
int i=0;
for (Novel novel : bookLists) {
if (novel.isFinished() || novel.isLocalBook() || novel.isUpdated()) {
if (novel.isFinished() || novel.isLocalBook() || (novel.isUpdated() && (new Date().getTime() - novel.getLastVisit() > 1*3600*1000 ))) {
continue;
}
if(i>Constants.MAX_SHELF_CNT){

View File

@ -16,8 +16,8 @@ public class AdSetting {
private slot fixBanner = new slot();
private slot bigBanner = new slot();
public boolean isShowAdsense() {
return true;
// return showAdsense && NetUtil.isNetworkConnected();
// return true;
return showAdsense && NetUtil.isNetworkConnected();
}
public void setShowAdsense(boolean showAdsense) {
@ -82,7 +82,7 @@ public class AdSetting {
private int displayPosition;
public int getDisplayPosition() {
//return 1;
// return 2;
return displayPosition;
}
@ -91,8 +91,8 @@ public class AdSetting {
}
public boolean isShow() {
return true;
// return show && NetUtil.isNetworkConnected();
// return true;
return show && NetUtil.isNetworkConnected();
}
public void setShow(boolean show) {
@ -100,8 +100,8 @@ public class AdSetting {
}
public int getSource() {
//return source;
return 1 ;
return source;
// return 1 ;
}
public void setSource(int source) {

View File

@ -375,12 +375,22 @@ public class BookUtil {
mChapters = NovelParseUtil.getChapters(mSite.getMuluUrl(), siteJson,mSite.getDomain(),maxAge,mSiteRule);
/* if (mChapters != null){
if (mChapters != null){
/* int i=0;
for (Chapter chapter:mChapters) {
Log.i(TAG, String.format("prepare book to get chaps readChaptersAsync %s-->%s",chapter.getChapterUrl(), chapter.getChapterName()));
i++;
// Log.i(TAG, String.format("prepare book to get chaps readChaptersAsync %s-->%s",chapter.getChapterUrl(), chapter.getChapterName()));
if(chapter.getChapterName().equals(mNovel.getChapterName())){
if(i<mChapters.size()-1){
mNovel.setChapterName(mChapters.get(mChapters.size()-1).getChapterName());
break;
}
}
}*/
checkLastUpdatedChapter();
}
} catch (JSONException e) {
Log.e(TAG, "prepare book error on parese :", e);
@ -390,6 +400,7 @@ public class BookUtil {
readChaptersAsync();
}else
{
mMuluStatus = MuluStatus.isDone;
handler.sendEmptyMessage(MSG_READCHAPTER_SUCCESS);
Log.d(TAG,String.format("prepare book loadChapts----end download %s 目录, 目录数量 %s, cost %s", mNovel.getName() , mChapters.size(), new Date().getTime() -startTime ));
@ -428,6 +439,23 @@ public class BookUtil {
}
private void checkLastUpdatedChapter() {
for (int i=mChapters.size()-1;i>0;i--) {
if(mChapters.get(i).getChapterName().equals(mNovel.getChapterName())){
if(i<mChapters.size()-1){
mNovel.setChapterName(mChapters.get(mChapters.size()-1).getChapterName());
Log.d(TAG, "prepare book: set novel lastchaptname " + mNovel.getLastReadChapt());
break;
}
}
}
if( mChapters.size()> mNovel.getChaptCnt()){
mNovel.setChaptCnt(mChapters.size());
mNovel.update(mNovel.getId());
}
}
public void setChapterNo(int chapterNo) {
this.chapterNo = chapterNo;
/*
@ -973,11 +1001,8 @@ int muluRetryCount =0;
mChapters = NovelParseUtil.getChapters(mSite.getDomain(),url, content, siteJson);
Log.d(TAG,String.format("mulu on Site %s download status %s",mSite.getDomain(),mMuluStatus));
if( mChapters.size()> mNovel.getChaptCnt()){
mNovel.setChaptCnt(mChapters.size());
mNovel.update(mNovel.getId());
}
checkLastUpdatedChapter();
} catch (JSONException e) {
// } catch (JSONException | IOException e) {
Log.e(TAG,String.format("prepare book, mulu on Site %s download status %s",mSite.getDomain(),mMuluStatus),e);

View File

@ -542,7 +542,7 @@ public class PageFactory implements ChangeSource{
int bannerPagecnt = Constants.AD_SETTING.getChapterBanner().getPageCount4Display();
int nativeBannerPageCnt =4;// Constants.AD_SETTING.getChapterContentBanner().getPageCount4Display();
int nativeBannerPageCnt = Constants.AD_SETTING.getChapterContentBanner().getPageCount4Display();
if (Constants.AD_SETTING.getChapterContentBanner().isShow() &&
nativeBannerPageCnt > 0 &&
mNavtiveBannerPlusCnt >= nativeBannerPageCnt) {