Commit 1cb23e3f authored by 王雪伟's avatar 王雪伟

更新aar

parent adc7c2e3
......@@ -28,9 +28,9 @@
</intent-filter>
</activity>
<!-- BlackBox 请在下面配置您的partnercode-->
<meta-data
android:name="PARTNER_CODE"
android:value="yanmao" />
<!-- <meta-data-->
<!-- android:name="PARTNER_CODE"-->
<!-- android:value="yanmao" />-->
</application>
</manifest>
\ No newline at end of file
package com.ym;
public class WXEntryActivity {
}
package com.ym.unityandroid;
import android.app.Activity;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
public class UnityWxLoginUtil {
private static volatile UnityWxLoginUtil sInstance;
private UnityWxLoginUtil() {
}
public static UnityWxLoginUtil getInstance() {
if (sInstance == null) {
synchronized (UnityWxLoginUtil.class) {
if (sInstance == null) {
sInstance = new UnityWxLoginUtil();
}
}
}
return sInstance;
}
// APP_ID 替换为你的应用从官方网站申请到的合法appID
public static String WxAPP_ID = "";
private IWXAPI api;
public void InitWxLogin(Activity activity, String WxAppId){
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
WxAPP_ID = WxAppId;
// 通过WXAPIFactory工厂,获取IWXAPI的实例
api = WXAPIFactory.createWXAPI(activity, WxAPP_ID, true);
// 将应用的appId注册到微信
api.registerApp(WxAPP_ID);
}
});
}
public void wxLogin(Activity activity){
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
final SendAuth.Req req = new SendAuth.Req();
req.scope = "snsapi_userinfo";
req.state = "wechat_sdk";
if (api!=null){
api.sendReq(req);
}
}
});
}
}
......@@ -25,5 +25,9 @@
android:layout_height="wrap_content"
android:text="test_DownLoad"></Button>
<FrameLayout
android:id="@+id/test_img_ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
\ No newline at end of file
......@@ -24,14 +24,23 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<!-- <provider-->
<!-- android:name="android.support.v4.content.FileProvider"-->
<!-- android:authorities="${applicationId}.fileProvider"-->
<!-- android:exported="false"-->
<!-- android:grantUriPermissions="true">-->
<!-- <meta-data-->
<!-- android:name="android.support.FILE_PROVIDER_PATHS"-->
<!-- android:resource="@xml/file_paths" />-->
<!-- </provider>-->
<!-- <provider-->
<!-- android:name="android.support.v4.content.FileProvider"-->
<!-- android:authorities="${applicationId}.fileProvider"-->
<!-- android:exported="false"-->
<!-- android:grantUriPermissions="true">-->
<!-- <meta-data-->
<!-- android:name="android.support.FILE_PROVIDER_PATHS"-->
<!-- android:resource="@xml/file_paths" />-->
<!-- </provider>-->
</application>
</manifest>
\ No newline at end of file
......@@ -4,7 +4,6 @@ import android.app.Activity;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Build;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebView;
......@@ -12,7 +11,7 @@ import android.webkit.WebView;
import java.net.URLEncoder;
public class AppliContext {
public class HcAppliContext {
public static Context mAppContext;
private static AppInstallReceive installedReceiver;
......@@ -34,18 +33,20 @@ public class AppliContext {
ZXHCConstant.device_imsi = PhoneUtils.getInstance().getIMSI(context);
ZXHCConstant.device_network = PhoneUtils.getInstance().getNetwork(context);
ZXHCConstant.device_os = "Android";
ZXHCConstant.device_os_version = Build.VERSION.SDK_INT + "";
ZXHCConstant.device_os_version = Build.VERSION.RELEASE + ".0.0";
ZXHCConstant.device_density = PhoneUtils.getInstance().getScreenDensity(context) + "";
ZXHCConstant.device_ppi = PhoneUtils.getInstance().getScreenDpi(context) + "";
ZXHCConstant.screen_size = PhoneUtils.getInstance().getScreenSize(context) + "";
ZXHCConstant.device_ip = PhoneUtils.getInstance().getIPAddress(false) + "";
ZXHCConstant.device_ua =toURLEncoded(new WebView(context).getSettings().getUserAgentString());
ZXHCConstant.device_report_ua =PhoneUtils.getInstance().getUserAgent(context);
ZXHCConstant.device_ua =toURLEncoded(PhoneUtils.getInstance().getUserAgent(context));
// ZXHCConstant.device_ua =toURLEncoded(new WebView(context).getSettings().getUserAgentString());
ZXHCConstant.device_type = "0";
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";
}
......
......@@ -12,14 +12,12 @@ import android.os.Build;
import android.os.Environment;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
import java.io.File;
import java.util.List;
import static android.content.Context.DOWNLOAD_SERVICE;
public class DownLoadUtils {
public class HcDownLoadUtils {
private DownloadManager downloadManager = null;
//下载的ID
......@@ -31,22 +29,21 @@ public class DownLoadUtils {
// private List<HcAdBean>
public DownLoadUtils(Activity activity) {
public HcDownLoadUtils(Activity activity) {
this.activity = activity;
//注册广播监测下载情况
activity.registerReceiver(receiver,
new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
this.downloadManager = (DownloadManager) AppliContext.get().getSystemService(DOWNLOAD_SERVICE);
this.downloadManager = (DownloadManager) HcAppliContext.get().getSystemService(DOWNLOAD_SERVICE);
}
//下载apk
public boolean downloadAPK(HcAdBean adBean) {
if (ZXHCConstant.adList.size()<=0){
return false;
}
// if (ZXHCConstant.adList.size()<=0){
// return false;
// }
for (int i = 0; i < ZXHCConstant.adList.size(); i++) {
if (ZXHCConstant.adList.get(i).getDUrl().equals(adBean.getDUrl())) {
// Log.d("wxw", "正在下载");
if (ZXHCConstant.adList.get(i).getDown_url().equals(adBean.getDown_url())) {
if (ZXHCConstant.adList.get(i).isDownOver()) {
try {
installAPK(ZXHCConstant.adList.get(i));
......@@ -89,6 +86,7 @@ public class DownLoadUtils {
adBean.setDownLoadId(downloadId);
}
DownLoadStartReport(adBean);
adBean.setDownOver(false);
ZXHCConstant.adList.add(adBean);
return true;
}
......
......@@ -68,7 +68,7 @@ public class HttpClientUtils {
connection.setConnectTimeout(30000);
connection.setReadTimeout(30000);
// User-Agent IE9的标识
//connection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;");
connection.setRequestProperty("User-Agent",ZXHCConstant.device_report_ua);
connection.setRequestProperty("Accept-Language", "zh-CN");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Charset", "UTF-8");
......@@ -142,7 +142,7 @@ public class HttpClientUtils {
connection.setConnectTimeout(50000);
connection.setReadTimeout(50000);
// User-Agent IE9的标识
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;");
connection.setRequestProperty("User-Agent", ZXHCConstant.device_report_ua);
connection.setRequestProperty("Accept-Language", "zh-CN");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Charset", "UTF-8");
......@@ -224,7 +224,6 @@ public class HttpClientUtils {
}
private static void getImg(String url, OnRequestImgCallBack callBack) {
Log.d("wxw","wxw"+url);
boolean isSuccess = false;
String message = "";
URL imgUrl = null;
......
......@@ -3,7 +3,6 @@ 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;
......@@ -24,6 +23,7 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Display;
import android.webkit.WebSettings;
import org.json.JSONArray;
import org.json.JSONException;
......@@ -255,7 +255,7 @@ public class PhoneUtils {
* @return App版本码
*/
public String getAppPackage() {
return AppliContext.get().getPackageName();
return HcAppliContext.get().getPackageName();
}
/**
......@@ -716,6 +716,28 @@ public class PhoneUtils {
}
}
public String getUserAgent(Context context) {
String userAgent = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
try {
userAgent = WebSettings.getDefaultUserAgent(context);
} catch (Exception e) {
userAgent = System.getProperty("http.agent");
}
} else {
userAgent = System.getProperty("http.agent");
}
StringBuffer sb = new StringBuffer();
for (int i = 0, length = userAgent.length(); i < length; i++) {
char c = userAgent.charAt(i);
if (c <= '\u001f' || c >= '\u007f') {
sb.append(String.format("\\u%04x", (int) c));
} else {
sb.append(c);
}
}
return sb.toString();
}
public String getLocationInfo(Context context, int type) {
//type =1 经度 2 纬度 3 城市
......
......@@ -26,6 +26,7 @@ public class ZXHCConstant {
public static String screen_size = "";
public static String device_ip = "";
public static String device_ua = "";
public static String device_report_ua = "";
public static String device_type = "";
public static String is_mobile = "";
public static String device_model = "";
......
package com.ym.zxhcsdk.manager;
import android.app.Activity;
import android.util.Log;
import com.ym.zxhcsdk.AppliContext;
import com.ym.zxhcsdk.HcAppliContext;
import com.ym.zxhcsdk.ZXHCConstant;
public class ZXHCADManager {
......@@ -22,9 +21,11 @@ public class ZXHCADManager {
}
return sInstance;
}
//1.3.5 修改上报链接替换
//1.3.6 删除aar中的FileProvider
public boolean InitAd(Activity context, String appId,boolean isDebug){
ZXHCConstant.ZXHC_APPID = appId;
AppliContext.init(context);
HcAppliContext.init(context);
ZXHCConstant.IS_DEBUG = isDebug;
if (ZXHCConstant.IS_DEBUG){
ZXHCConstant.BASE_URL = "http://sspv2test.zhangxinhuichuan.com/ssp/v1/ads";
......
......@@ -14,7 +14,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.ym.zxhcsdk.DownLoadUtils;
import com.ym.zxhcsdk.HcDownLoadUtils;
import com.ym.zxhcsdk.HcAdBean;
import com.ym.zxhcsdk.HttpClientUtils;
import com.ym.zxhcsdk.PhoneUtils;
......@@ -104,13 +104,13 @@ public class ZXHCFeedAD {
public void destroyFeedAd(ViewGroup feedVp) {
if (feedVp != null) {
ZXHCAdViewManager.getInstance().removeAdView(context, feedVp);
context.runOnUiThread(new Runnable() {
@Override
public void run() {
listener.OnAdClosed();
}
});
ZXHCAdViewManager.getInstance().removeAdView(context, feedVp);
} else {
Log.d("wxw", "feedAd null");
}
......@@ -129,7 +129,6 @@ public class ZXHCFeedAD {
TextView desc = view.findViewById(R.id.id_ad_feed_desc);
TextView title = view.findViewById(R.id.id_ad_feed_title);
Log.d("wxw", "adBean.getContent()" + adBean.getContent() + "adBean.getApp_name()" + adBean.getApp_name());
desc.setText(adBean.getContent());
title.setText(adBean.getTitle());
ImageView feedImg = view.findViewById(R.id.id_ad_feed_img);
......@@ -188,7 +187,6 @@ public class ZXHCFeedAD {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.width = width;
layoutParams.height = height;
Log.d("wxw", "width" + width + "height" + height);
view.setLayoutParams(layoutParams);
}
});
......@@ -210,12 +208,11 @@ public class ZXHCFeedAD {
}catch (ClassCastException exception){
exception.printStackTrace();
}
}
});
}
} else if (adBean.getTarget_type().equals("1")) {
new DownLoadUtils(context).downloadAPK(adBean);
new HcDownLoadUtils(context).downloadAPK(adBean);
}
}
} else {
......@@ -240,12 +237,11 @@ public class ZXHCFeedAD {
}catch (ClassCastException exception){
exception.printStackTrace();
}
}
});
}
} else if (adBean.getTarget_type().equals("1")) {
new DownLoadUtils(context).downloadAPK(adBean);
new HcDownLoadUtils(context).downloadAPK(adBean);
}
}
}
......
......@@ -14,7 +14,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.ym.zxhcsdk.DownLoadUtils;
import com.ym.zxhcsdk.HcDownLoadUtils;
import com.ym.zxhcsdk.HcAdBean;
import com.ym.zxhcsdk.HttpClientUtils;
import com.ym.zxhcsdk.PhoneUtils;
......@@ -233,7 +233,7 @@ public class ZXHCSplashAD {
@Override
public void run() {
try {
Intent intent = new Intent(context, HcWebActivity.class);
Intent intent = new Intent(context, HcWebActivity.class);
intent.putExtra("url",adBean.getDUrl().get(0));
context.startActivity(intent);
}catch (ClassCastException exception){
......@@ -348,7 +348,7 @@ public class ZXHCSplashAD {
}
private void DownLoadApk() {
new DownLoadUtils(context).downloadAPK(adBean);
new HcDownLoadUtils(context).downloadAPK(adBean);
}
......
......@@ -2,15 +2,29 @@ package com.ym.zxhcsdk.webview;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.ym.zxhcsdk.HcAppliContext;
import com.ym.zxhcsdk.R;
import com.ym.zxhcsdk.ZXHCConstant;
import java.util.List;
import java.util.Locale;
public class HcWebActivity extends Activity {
private String url;
......@@ -25,7 +39,26 @@ public class HcWebActivity extends Activity {
webView = findViewById(R.id.activity_webview);
initTitle();
initWebView();
webView.loadUrl(url);
webView.loadUrl(releactReportUrl(url));
}
//上报参数替换
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;
}
private void initWebView() {
......@@ -51,23 +84,42 @@ public class HcWebActivity extends Activity {
webView.getSettings().setJavaScriptEnabled(true);
// 建立JavaScript调用Java接口的桥梁。
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
try {
// API 7, LocalStorage/SessionStorage
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
// webSettings.setDatabasePath(HcAppliContext.get().filesDir.absolutePath + "/webcache");
// API 7, Web SQL Database, 需要重载方法(WebChromeClient)才能生效,无法只通过反射实现
} catch (Exception e) {
}
webView.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
WebView.WebViewTransport transport = (WebView.WebViewTransport)resultMsg.obj;
transport.setWebView(webView);
resultMsg.sendToTarget();
return true;
}
});
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(url));
startActivity(intent);
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
// Uri uri = Uri.parse(url);
// Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// startActivity(intent);
// Log.d("wxw","0urllll "+url);
} catch (Exception e) {
Log.d("wxw","1urllll "+url);
if (url!=null){
if (shouldOverrideUrlLoadingByApp(url)) {
return true;
}
}
Log.d("wxw","2urllll "+url);
view.loadUrl(url);
return false;
return super.shouldOverrideUrlLoading(view, url);
}
});
// webView.loadDataWithBaseURL(null, url, "text/html", "utf-8", null);//解决乱码问题
......@@ -110,5 +162,26 @@ public class HcWebActivity extends Activity {
}
private boolean shouldOverrideUrlLoadingByApp(String url){
try {
if (!url.startsWith("http") && !url.startsWith("https") && !url.startsWith("ftp")) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
if (isInstall(intent)) {
this.startActivity(intent);
return true;
}
} else {
return false;
}
} catch (Exception e ) {
return false;
}
return false;
}
//判断app是否安装
public static Boolean isInstall(Intent intent) {
return HcAppliContext.get().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
}
}
\ No newline at end of file
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