Commit eefe0692 authored by 王雪伟's avatar 王雪伟

DpLink跳转异常上报,加入跳转WebView

parent 86747623
......@@ -12,6 +12,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.ym.zxhcsdk.HttpClientUtils;
import com.ym.zxhcsdk.PhoneUtils;
import com.ym.zxhcsdk.ZXHCConstant;
import com.ym.zxhcsdk.listener.FeedAdListener;
......@@ -25,6 +26,7 @@ import java.io.File;
public class MainActivity extends Activity {
ZXHCFeedAD feedAD1;
ViewGroup vp;
ZXHCSplashAD zxhcSplashAD;
@Override
......@@ -32,30 +34,31 @@ public class MainActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ZXHCADManager.getInstance().InitAd(this, "1000127",false);
// ZXHCADManager.getInstance().InitAd(this, "1000127", true);
ZXHCADManager.getInstance().InitAd(this, "1000127", true);
String url = "http://sspv2test.zhangxinhuichuan.com/ssp/v1/ads?pid=2100154&type=api&ad_type=3&ad_w=480&ad_h=720&app_package=com.popcap.pvz2cthd&app_id=1000127&app_name=com.popcap.pvz2cthd&app_versionid=1005&device_geo_lat=&device_geo_lon=&device_imei=X6GNU17524105082&device_adid=d0cf1c3d5280f16b&device_mac=F0:C8:50:A1:4E:8E&device_width=1920&device_height=1132&device_imsi=460000501365163&device_carrier=&device_network=1&device_os=Android&device_os_version=24&device_density=2.0&device_ppi=2.0&device_ip=183.211.87.156&device_ua=Dalvik%2F2.1.0+%28Linux%3B+U%3B+Android+9%3B+Redmi+Note+8+Pro+MIUI%2FV10.4.9.0.PGGCNXM%29&device_type=0&is_mobile=1&device_model=FLA-AL10&device_brand=HUAWEI";
String BaseUrl = "http://sspv2test.zhangxinhuichuan.com/ssp/v1/ads";
new OaidUtils().GetOaid(MainActivity.this, new IOaidListener() {
@Override
public void getOaid(String oaid) {
Log.d("wxw","oaid"+oaid);
Log.d("wxw", "oaid" + oaid);
ZXHCConstant.device_oaid = oaid;
}
});
findViewById(R.id.test_DownLoad).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
feedAD1.destroyFeedAd(vp);
}
});
findViewById(R.id.test_Feed).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
feedAD1 = new ZXHCFeedAD(MainActivity.this, "2100155", 1080, 720, new FeedAdListener() {
feedAD1 = new ZXHCFeedAD(MainActivity.this, "2100156", 1080, 720, new FeedAdListener() {
@Override
public void OnAdLoaded() {
ViewGroup vp = ZXHCAdViewManager.getInstance().newFrameLayout(MainActivity.this);
vp = ZXHCAdViewManager.getInstance().newFrameLayout(MainActivity.this);
ZXHCAdViewManager.getInstance().showAdView(MainActivity.this, vp, true);
feedAD1.showAd(vp);
}
......
......@@ -15,6 +15,17 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application>
<activity
android:name=".webview.WebActivity"
android:exported="true"
android:screenOrientation="fullSensor"
android:theme="@android:style/Theme.Light.NoTitleBar"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileProvider"
......
......@@ -14,7 +14,9 @@ public class AppInstallReceive extends BroadcastReceiver {
if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_ADDED)){
String packageName = intent.getData().getSchemeSpecificPart();
if (!TextUtils.isEmpty(packageName)) {
Log.d("wxw","安装完成"+ZXHCConstant.adList.size());
for (int i =0;i<ZXHCConstant.adList.size();i++){
Log.d("wxw","安装完成"+ZXHCConstant.adList.get(0).getPackage_name());
if (packageName.equals(ZXHCConstant.adList.get(i).getPackage_name())){
InstallFinishReport(ZXHCConstant.adList.get(i));
ZXHCConstant.adList.remove(i);
......@@ -26,13 +28,13 @@ public class AppInstallReceive extends BroadcastReceiver {
if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_REMOVED)){
String packageName = intent.getData().getSchemeSpecificPart();
if (!TextUtils.isEmpty(packageName)) {
Log.d("wxw","ACTION_PACKAGE_REMOVED"+ZXHCConstant.adList.size());
}
}
if (TextUtils.equals(intent.getAction(),Intent.ACTION_PACKAGE_REPLACED)){
String packageName = intent.getData().getSchemeSpecificPart();
if (!TextUtils.isEmpty(packageName)) {
Log.d("wxw","ACTION_PACKAGE_REPLACED"+ZXHCConstant.adList.size());
}
}
// intent.getAction()
......
......@@ -45,8 +45,14 @@ public class AppliContext {
ZXHCConstant.is_mobile = "1";
ZXHCConstant.device_model = PhoneUtils.getInstance().getModel();
ZXHCConstant.device_brand = Build.BRAND;
ZXHCConstant.device_geo_lon = PhoneUtils.getInstance().getLocationInfo(context, 1);
ZXHCConstant.device_geo_lon=PhoneUtils.getInstance().getLocationInfo(context, 1);
if (TextUtils.isEmpty(ZXHCConstant.device_geo_lon)){
ZXHCConstant.device_geo_lon="-999";
}
ZXHCConstant.device_geo_lat = PhoneUtils.getInstance().getLocationInfo(context, 2);
if (TextUtils.isEmpty(ZXHCConstant.device_geo_lat)){
ZXHCConstant.device_geo_lat="-999";
}
ZXHCConstant.device_geo_city = PhoneUtils.getInstance().getLocationInfo(context, 3);
installedReceiver = new AppInstallReceive();
IntentFilter filter = new IntentFilter();
......
......@@ -76,7 +76,6 @@ public class DownLoadUtils {
}
request.setDestinationUri(Uri.fromFile(file));
String filePath = file.getAbsolutePath();
Log.d("wxw", "filePath " + filePath);
adBean.setDownLoadFilePath(filePath);
//获取DownloadManager
if (downloadManager == null)
......@@ -148,9 +147,8 @@ public class DownLoadUtils {
// 由于没有在Activity环境下启动Activity,设置下面的标签
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//Android 7.0以上要使用FileProvider
File file = new File(adBean.getDownLoadFilePath());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Log.d("wxw", "getDownLoadFilePath" + adBean.getDownLoadFilePath());
File file = new File(adBean.getDownLoadFilePath());
//参数1 上下文, 参数2 Provider主机地址 和配置文件中保持一致 参数3 共享的文件
Uri apkUri = FileProvider.getUriForFile(activity, PhoneUtils.getInstance().getAppPackage() + ".fileProvider", file);
//添加这一句表示对目标应用临时授权该Uri所代表的文件
......
......@@ -22,7 +22,7 @@ public class HttpClientUtils {
public static void GetEvent(String url) {
new Thread() {
public void run() {
getRequest(url, new OnRequestCallBack() {
getRequest(releactReportUrl(url), new OnRequestCallBack() {
@Override
public void onSuccess(String json) {
// Log.d("wxw", "GetEvent url"+url);
......@@ -31,8 +31,8 @@ public class HttpClientUtils {
@Override
public void onError(String errorMsg) {
Log.d("wxw", "GetEvent url" + url);
Log.d("wxw", "GetEvent errorMsg" + errorMsg);
// Log.d("wxw", "GetEvent url" + url);
// Log.d("wxw", "GetEvent errorMsg" + errorMsg);
}
});
}
......@@ -65,6 +65,7 @@ public class HttpClientUtils {
URL url = new URL(requestUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setInstanceFollowRedirects(true);
connection.setConnectTimeout(50000);
connection.setReadTimeout(50000);
// User-Agent IE9的标识
......@@ -275,7 +276,7 @@ public class HttpClientUtils {
void onError(String errorMsg);
}
//添加公共参数
public static String addParams(Map<String, String> request) {
if (request == null) {
request = new HashMap<>();
......@@ -344,5 +345,24 @@ public class HttpClientUtils {
str = str.substring(0, str.length() - 1);
return str;
}
//上报参数替换
private static String releactReportUrl(String url){
url = url.replace("__RE_DOWN_X__", ZXHCConstant.downX + "");//手指按下时相对于广告位左上角的横坐标
url = url.replace("__RE_DOWN_Y__", ZXHCConstant.downY + "");//手指按下时相对于广告位左上角的纵坐标
url = url.replace("__RE_UP_X__", ZXHCConstant.upX + "");//手指抬起时相对于广告位左上角的横坐标
url = url.replace("__RE_UP_Y__", ZXHCConstant.upY + "");//手指抬起时相对于广告位左上角的纵坐标
url = url.replace("__DOWN_X__", ZXHCConstant.downRawX + "");//手指按下时相对于屏幕左上角的横坐标
url = url.replace("__DOWN_Y__", ZXHCConstant.downRawY + "");//手指按下时相对于屏幕左上角的纵坐标
url = url.replace("__UP_X__", ZXHCConstant.upRawX + "");//手指抬起时相对于屏幕左上角的横坐标
url = url.replace("__UP_Y__", ZXHCConstant.upRawY + "");//手指抬起时相对于屏幕左上角的纵坐标
url = url.replace("__UTC_TS__", System.currentTimeMillis() + "");//客户端触发时间戳,自 1970 年起的毫秒 ,13 位
url = url.replace("__UTC_TS_SECOND__", System.currentTimeMillis() / 1000 + "");//客户端触发时间戳,自 1970 年起的秒 ,10 位
url = url.replace("__WIDTH__", "-999");//实际广告位的宽,单位为像素
url = url.replace("__HEIGHT__", "-999");//实际广告位的高,单位为像素
url = url.replace("__LATITUDE__", ZXHCConstant.device_geo_lat);//地理位置信息, 纬度
url = url.replace("__LONGITUDE__", ZXHCConstant.device_geo_lon);//地理位置信息, 经度
url = url.replace("__IP__", ZXHCConstant.device_ip);
return url;
}
}
......@@ -3,6 +3,7 @@ package com.ym.zxhcsdk;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
......@@ -712,7 +713,7 @@ public class PhoneUtils {
public String getLocationInfo(Context context, int type) {
//type =1 经度 2 纬度
//type =1 经度 2 纬度 3 城市
String locationProvider;
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// 获取所有可用的位置提供器
......@@ -776,4 +777,22 @@ public class PhoneUtils {
return ZXHCConstant.device_oaid;
}
public boolean IsInstallApp(Context context, String pkgName){
if (pkgName== null || pkgName.isEmpty()) {
return false;
}
PackageInfo packageInfo;
try {
packageInfo = context.getPackageManager().getPackageInfo(pkgName, 0);
} catch (PackageManager.NameNotFoundException e) {
packageInfo = null;
e.printStackTrace();
}
if(packageInfo == null) {
return false;
} else {
return true;//true为安装了,false为未安装
}
}
}
......@@ -9,7 +9,6 @@ public class ZXHCConstant {
public static String BASE_URL = "";
public static String app_package = "";
public static String app_name = "";
public static String app_version = "";
......@@ -31,25 +30,21 @@ public class ZXHCConstant {
public static String is_mobile = "";
public static String device_model = "";
public static String device_brand = "";
public static String device_geo_lat = "";
public static String device_geo_lon = "";
public static String device_geo_lat = "-999";
public static String device_geo_lon = "-999";
public static String device_geo_city = "";
public static String device_oaid = "";
public static ArrayList<HcAdBean> adList = new ArrayList<>();
public static String downX = "-999";
public static String downY = "-999";
public static String downRawX = "-999";
public static String downRawY = "-999";
public static String upX = "-999";
public static String upY = "-999";
public static String upRawX = "-999";
public static String upRawY = "-999";
}
package com.ym.zxhcsdk.webview;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.util.AttributeSet;
import android.webkit.WebView;
public class CustomWebView extends WebView {
public CustomWebView(Context context) {
super(getFixedContext(context));
}
public CustomWebView(Context context, AttributeSet attrs) {
super(getFixedContext(context), attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(getFixedContext(context), attrs, defStyleAttr);
}
public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);
}
public static Context getFixedContext(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setWebContentsDebuggingEnabled(true);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return context.createConfigurationContext(new Configuration());
} else {
return context;
}
}
}
package com.ym.zxhcsdk.webview;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import com.ym.zxhcsdk.R;
public class WebActivity extends Activity {
private String url;
private String title;
private CustomWebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_web);
url = getIntent().getStringExtra("url");
title = getIntent().getStringExtra("title");
webView = findViewById(R.id.activity_webview);
initTitle();
initWebView();
webView.loadUrl(url);
}
private void initWebView() {
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
// webView.getSettings().setDefaultFontSize(56);
// webView.getSettings().setMinimumFontSize(40);//设置最小字体
// 建议禁止缓存加载,以确保在攻击发生时可快速获取最新的滑动验证组件进行对抗。
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
// 设置不使用默认浏览器,而直接使用WebView组件加载页面。
// 设置WebView组件支持加载JavaScript。
webView.getSettings().setJavaScriptEnabled(true);
// 建立JavaScript调用Java接口的桥梁。
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
// webView.loadDataWithBaseURL(null, url, "text/html", "utf-8", null);//解决乱码问题
}
private void initTitle() {
findViewById(R.id.iv_user_toolbar_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
TextView tv_title = findViewById(R.id.tv_user_toolbar_title);
// tv_title.setText(title + "");
}
@Override
protected void onResume() {
super.onResume();
if (webView != null) {
webView.loadUrl("javascript:onResume()");
}
}
@Override
protected void onPause() {
super.onPause();
if (webView != null) {
webView.loadUrl("javascript:onPause()");
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (webView != null) {
webView.destroy();
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".webview.WebActivity">
<RelativeLayout
android:id="@+id/id_rl_toolbar"
android:layout_width="match_parent"
android:layout_height="50dp">
<ImageView
android:id="@+id/iv_user_toolbar_back"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:src="@mipmap/arrow_left" />
<TextView
android:id="@+id/tv_user_toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<com.ym.zxhcsdk.webview.CustomWebView
android:id="@+id/activity_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
\ No newline at end of file
......@@ -28,22 +28,24 @@
<LinearLayout
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:gravity="center_vertical">
<TextView
android:id="@+id/id_ad_feed_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaaaaa"
android:layout_weight="1"
android:text="aaaaaaaaa"
android:textColor="#000000"
android:textSize="16dp" />
<ImageView
android:id="@+id/id_ad_feed_close"
android:layout_width="wrap_content"
android:src="@mipmap/feedad_close"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:src="@mipmap/feedad_close" />
</LinearLayout>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment