|
|
@@ -1,1151 +0,0 @@
|
|
|
-/****************************************************************************
|
|
|
-Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
-Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
-
|
|
|
-http://www.cocos2d-x.org
|
|
|
-
|
|
|
-Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
-of this software and associated documentation files (the "Software"), to deal
|
|
|
-in the Software without restriction, including without limitation the rights
|
|
|
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
-copies of the Software, and to permit persons to whom the Software is
|
|
|
-furnished to do so, subject to the following conditions:
|
|
|
-
|
|
|
-The above copyright notice and this permission notice shall be included in
|
|
|
-all copies or substantial portions of the Software.
|
|
|
-
|
|
|
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
-THE SOFTWARE.
|
|
|
-****************************************************************************/
|
|
|
-package org.cocos2dx.javascript;
|
|
|
-import org.cocos2dx.javascript.config.ContextWrapperUtil;
|
|
|
-import org.com.aries.hyxy.mz.Util;
|
|
|
-import org.cocos2dx.javascript.config.MiitHelper;
|
|
|
-import org.cocos2dx.javascript.config.SplashAdShowActivity;
|
|
|
-import org.cocos2dx.javascript.config.SwitchManager;
|
|
|
-import org.cocos2dx.javascript.config.TTAdManagerHolder;
|
|
|
-import org.cocos2dx.lib.Cocos2dxActivity;
|
|
|
-import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
|
|
|
-import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge;
|
|
|
-import org.json.JSONException;
|
|
|
-import org.json.JSONObject;
|
|
|
-
|
|
|
-import android.Manifest;
|
|
|
-import android.annotation.SuppressLint;
|
|
|
-import android.content.ClipData;
|
|
|
-import android.content.ClipboardManager;
|
|
|
-import android.content.Context;
|
|
|
-import android.content.pm.PackageInfo;
|
|
|
-import android.content.pm.PackageManager;
|
|
|
-import android.graphics.Bitmap;
|
|
|
-import android.graphics.BitmapFactory;
|
|
|
-import android.net.ConnectivityManager;
|
|
|
-import android.net.Network;
|
|
|
-import android.net.NetworkCapabilities;
|
|
|
-import android.net.Uri;
|
|
|
-import android.net.wifi.WifiInfo;
|
|
|
-import android.net.wifi.WifiManager;
|
|
|
-import android.os.Build;
|
|
|
-import android.os.Bundle;
|
|
|
-
|
|
|
-import android.content.Intent;
|
|
|
-import android.content.res.Configuration;
|
|
|
-import android.os.Handler;
|
|
|
-import android.os.Message;
|
|
|
-import android.provider.Settings;
|
|
|
-import android.telephony.TelephonyManager;
|
|
|
-import android.util.Log;
|
|
|
-import android.view.Gravity;
|
|
|
-import android.view.KeyEvent;
|
|
|
-import android.webkit.WebSettings;
|
|
|
-import android.webkit.WebView;
|
|
|
-import android.widget.Toast;
|
|
|
-
|
|
|
-
|
|
|
-import androidx.annotation.NonNull;
|
|
|
-import androidx.core.app.ActivityCompat;
|
|
|
-import androidx.core.content.ContextCompat;
|
|
|
-import androidx.core.content.FileProvider;
|
|
|
-import androidx.multidex.MultiDex;
|
|
|
-
|
|
|
-import com.anythink.core.api.ATSDK;
|
|
|
-import com.aries.hyxy.mz.BuildConfig;
|
|
|
-import com.aries.hyxy.mz.R;
|
|
|
-import com.bun.miitmdid.core.JLibrary;
|
|
|
-import com.bytedance.embedapplog.AppLog;
|
|
|
-import com.bytedance.embedapplog.GameReportHelper;
|
|
|
-import com.fm.openinstall.OpenInstall;
|
|
|
-import com.fm.openinstall.listener.AppInstallAdapter;
|
|
|
-import com.fm.openinstall.listener.AppWakeUpAdapter;
|
|
|
-import com.fm.openinstall.model.AppData;
|
|
|
-import com.kwai.monitor.log.TurboAgent;
|
|
|
-import com.kwai.monitor.log.TurboConfig;
|
|
|
-import com.qq.gdt.action.ActionType;
|
|
|
-import com.qq.gdt.action.ActionUtils;
|
|
|
-import com.qq.gdt.action.GDTAction;
|
|
|
-import com.tencent.mm.opensdk.modelmsg.SendAuth;
|
|
|
-import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
|
|
|
-import com.tencent.mm.opensdk.modelmsg.WXImageObject;
|
|
|
-import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
|
|
|
-import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
|
|
|
-import com.tencent.mm.opensdk.openapi.IWXAPI;
|
|
|
-import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.InputStreamReader;
|
|
|
-import java.io.LineNumberReader;
|
|
|
-import java.net.URL;
|
|
|
-import java.net.URLConnection;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Locale;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-import cn.thinkingdata.android.TDConfig;
|
|
|
-import cn.thinkingdata.android.ThinkingAnalyticsSDK;
|
|
|
-
|
|
|
-import static org.com.aries.hyxy.mz.Util.bmpToByteArray;
|
|
|
-
|
|
|
-public class AppActivity extends Cocos2dxActivity {
|
|
|
- private static final int PERMISSIONS_REQUEST_STORAGE = 1;
|
|
|
- private IWXAPI api;
|
|
|
- private String userID;
|
|
|
-
|
|
|
- private final String TA_APP_ID = "3b44e7a0e4f942adb426804c0de8c08f";
|
|
|
- private final String TA_SERVER_URL = "https://taapi.mokagm.com/";
|
|
|
- private ThinkingAnalyticsSDK TAinstance;
|
|
|
-
|
|
|
- //快手是否初始化
|
|
|
- public boolean isTurboInit = false;
|
|
|
- //巨量是否初始化
|
|
|
- public boolean isAppLogInit = false;
|
|
|
-
|
|
|
- private int permissonNum = 0;
|
|
|
- private String mOAID = "";
|
|
|
-
|
|
|
- private static boolean isSupportOaid=true;
|
|
|
- private static int errorCode;
|
|
|
-
|
|
|
- private int end_duration = 0;
|
|
|
- private int duration = 0;
|
|
|
- //是否可以显示插屏 1 可以
|
|
|
- public int canShowSlash = 0;
|
|
|
-
|
|
|
- //游戏时间
|
|
|
- private int playTimeStart = 0;
|
|
|
- private int playTimeEnd = 0;
|
|
|
-
|
|
|
- AppWakeUpAdapter wakeUpAdapter = new AppWakeUpAdapter() {
|
|
|
- @Override
|
|
|
- public void onWakeUp(AppData appData) {
|
|
|
- Log.v("OpenInstall","fefefefefefefefe");
|
|
|
- //获取渠道数据
|
|
|
- String channelCode = appData.getChannel();
|
|
|
- //获取绑定数据
|
|
|
- String bindData = appData.getData();
|
|
|
- Log.d("OpenInstall", "getWakeUp : wakeupData = " + appData.toString());
|
|
|
-
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
-
|
|
|
- permissonNum = 0;
|
|
|
- isTurboInit = false;
|
|
|
- isAppLogInit = false;
|
|
|
-
|
|
|
- if (!isTaskRoot()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // DO OTHER INITIALIZATION BELOW
|
|
|
- SDKWrapper.getInstance().init(this);
|
|
|
-
|
|
|
- OpenInstall.init(this);
|
|
|
-
|
|
|
- TTAdManagerHolder.appAc = this;
|
|
|
-
|
|
|
- regToWx();
|
|
|
-
|
|
|
- TDConfig config = TDConfig.getInstance(this, TA_APP_ID, TA_SERVER_URL);
|
|
|
- TAinstance = ThinkingAnalyticsSDK.sharedInstance(config);
|
|
|
-
|
|
|
- //获取OAID等设备标识符
|
|
|
- MiitHelper miitHelper = new MiitHelper(appIdsUpdater);
|
|
|
- miitHelper.getDeviceIds(this);
|
|
|
-// ATSDK.setNetworkLogDebug(true);
|
|
|
- OpenInstall.getWakeUp(getIntent(), wakeUpAdapter);
|
|
|
- registerMainInstance();
|
|
|
-
|
|
|
- ToolHelp.Init(this);
|
|
|
- }
|
|
|
-
|
|
|
- private MiitHelper.AppIdsUpdater appIdsUpdater = new MiitHelper.AppIdsUpdater() {
|
|
|
- @Override
|
|
|
- public void OnIdsAvalid(@NonNull String ids) {
|
|
|
- Log.e("++++++ids: ", ids);
|
|
|
- mOAID = ids;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- public static String getErrorCode() {
|
|
|
- return String.valueOf(errorCode);
|
|
|
- }
|
|
|
-
|
|
|
- public static boolean isSupportOaid() {
|
|
|
- return isSupportOaid;
|
|
|
- }
|
|
|
-
|
|
|
- public static void setIsSupportOaid(boolean isSupportOaid) {
|
|
|
- AppActivity.isSupportOaid = isSupportOaid;
|
|
|
- }
|
|
|
- public static void setIsSupportOaid(boolean isSupportOaid,int ErrorCode) {
|
|
|
- AppActivity.isSupportOaid = isSupportOaid;
|
|
|
- AppActivity.errorCode=ErrorCode;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断当前wifi是否是处于可以使用状态
|
|
|
- *
|
|
|
- * @param context
|
|
|
- * @return
|
|
|
- */
|
|
|
- public boolean isWIFIConnection(Context context) {
|
|
|
- ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
- boolean isWifi = false;
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
- if (manager != null) {
|
|
|
- Network networks = manager.getActiveNetwork();
|
|
|
- NetworkCapabilities networkCapabilities = manager.getNetworkCapabilities(networks);
|
|
|
- if (networkCapabilities != null) {
|
|
|
- if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
|
|
|
- Log.e("-----------wifi", "wifi");
|
|
|
- isWifi = true;
|
|
|
- } else if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
|
|
- Log.e("-----------流量", "手机流量");
|
|
|
- }
|
|
|
- } else {
|
|
|
- Log.e("------------没有网络", "没有网络");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return isWifi;
|
|
|
- }
|
|
|
-
|
|
|
- private String getAppInfo() {
|
|
|
- try {
|
|
|
- String pkName = this.getPackageName();
|
|
|
- String versionName = this.getPackageManager().getPackageInfo(
|
|
|
- pkName, 0).versionName;
|
|
|
- int versionCode = this.getPackageManager()
|
|
|
- .getPackageInfo(pkName, 0).versionCode;
|
|
|
- return pkName ;
|
|
|
- } catch (Exception e) {
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void attachBaseContext(Context base) {
|
|
|
- super.attachBaseContext(base);
|
|
|
-
|
|
|
- MultiDex.install(this);
|
|
|
- JLibrary.InitEntry(base);
|
|
|
- }
|
|
|
-
|
|
|
- public void setUserID(String id){
|
|
|
- this.userID = id;
|
|
|
-
|
|
|
- if(BuildConfig.TF_CHANNEL.equals("1")){
|
|
|
- GameReportHelper.onEventLogin("",true); // 登录
|
|
|
- AppLog.setUserUniqueID(this.userID); // 设置您自己的账号体系ID或设备ID, 并保证其唯一性 !
|
|
|
- }
|
|
|
- else if(BuildConfig.TF_CHANNEL.equals("3")){
|
|
|
- ActionUtils.onLogin("", true);
|
|
|
- GDTAction.setUserUniqueId(this.userID); // 参数是用户软ID
|
|
|
- }
|
|
|
-
|
|
|
- setTAAccount();
|
|
|
- checkPermission();
|
|
|
- }
|
|
|
-
|
|
|
- public void startUpdatMachine(){
|
|
|
- String ANDROID_ID = Settings.System.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
|
|
|
-
|
|
|
- //获取IMEI号
|
|
|
- String imei1 = getImei(this);
|
|
|
-
|
|
|
- String mac = getMac(this);
|
|
|
-
|
|
|
- String versionName = getVersionName(this);
|
|
|
-
|
|
|
- String umengChannel = BuildConfig.UM_CHANNEL;
|
|
|
- String deviceType = getSystemVersion();
|
|
|
- String androidVersion = getSystemModel();
|
|
|
- String UA = getUA();
|
|
|
- updateMachine(ANDROID_ID, "", imei1, mac, mOAID, BuildConfig.UM_AID, versionName, umengChannel, deviceType, androidVersion, UA);
|
|
|
-
|
|
|
- if(imei1.equals("")){
|
|
|
- if(mOAID.equals("")){
|
|
|
- setTADeviceID(ANDROID_ID);
|
|
|
- }
|
|
|
- else{
|
|
|
- setTADeviceID(mOAID);
|
|
|
- }
|
|
|
- }
|
|
|
- else{
|
|
|
- setTADeviceID(imei1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private String getUA(){
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
|
|
|
- {
|
|
|
- return WebSettings.getDefaultUserAgent(this);
|
|
|
- } else {
|
|
|
- return new WebView(this).getSettings().getUserAgentString();
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- * 获取当前手机系统版本号
|
|
|
- *
|
|
|
- * @return 系统版本号
|
|
|
- */
|
|
|
- public static String getSystemVersion() {
|
|
|
- return android.os.Build.VERSION.RELEASE;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取手机型号
|
|
|
- *
|
|
|
- * @return 手机型号
|
|
|
- */
|
|
|
- public static String getSystemModel() {
|
|
|
- return android.os.Build.MODEL;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * get App versionName
|
|
|
- * @param context
|
|
|
- * @return
|
|
|
- */
|
|
|
- public String getVersionName(Context context){
|
|
|
- PackageManager packageManager=context.getPackageManager();
|
|
|
- PackageInfo packageInfo;
|
|
|
- String versionName="";
|
|
|
- try {
|
|
|
- packageInfo=packageManager.getPackageInfo(context.getPackageName(),0);
|
|
|
- versionName=packageInfo.versionName;
|
|
|
- } catch (PackageManager.NameNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return versionName;
|
|
|
- }
|
|
|
-
|
|
|
- //-------- 获取mac地址--------
|
|
|
- public String getMac(Context context) {
|
|
|
-
|
|
|
- String strMac = null;
|
|
|
-
|
|
|
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
|
- Log.e("=====", "6.0以下");
|
|
|
- Toast.makeText(context, "6.0以下", Toast.LENGTH_SHORT).show();
|
|
|
- strMac = getLocalMacAddressFromWifiInfo(context);
|
|
|
- return strMac;
|
|
|
- } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
- Log.e("=====", "7.0以上");
|
|
|
- strMac = getMac();
|
|
|
- return strMac;
|
|
|
- }
|
|
|
-
|
|
|
- return "02:00:00:00:00:00";
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据wifi信息获取本地mac
|
|
|
- * @param context
|
|
|
- * @return
|
|
|
- */
|
|
|
- public String getLocalMacAddressFromWifiInfo(Context context){
|
|
|
- WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
|
|
- WifiInfo winfo = wifi.getConnectionInfo();
|
|
|
- String mac = winfo.getMacAddress();
|
|
|
- return mac;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 这是使用adb shell命令来获取mac地址的方式
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static String getMac() {
|
|
|
- String macSerial = null;
|
|
|
- String str = "";
|
|
|
- String macAll = "";
|
|
|
-
|
|
|
- try {
|
|
|
- Process pp = Runtime.getRuntime().exec("ip addr");
|
|
|
- InputStreamReader ir = new InputStreamReader(pp.getInputStream());
|
|
|
- LineNumberReader input = new LineNumberReader(ir);
|
|
|
- for (; null != str; ) {
|
|
|
- str = input.readLine();
|
|
|
-// Log.d("vvvvvvvvv ", "getMac: " + str);
|
|
|
- if (str != null) {
|
|
|
- macSerial = str.trim();// 去空格
|
|
|
- if(macSerial.indexOf("link/ether") != -1) {
|
|
|
- if(macSerial.split(" ").length >= 2){
|
|
|
- if(macAll.equals("")){
|
|
|
- macAll = macSerial.split(" ")[1];
|
|
|
- }
|
|
|
- else{
|
|
|
- macAll = macAll.concat(",").concat(macSerial.split(" ")[1]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- } catch (IOException ex) {
|
|
|
- // 赋予默认值
|
|
|
- ex.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- Log.d("vvvvvvvvv111 ", "getMac: " + macAll);
|
|
|
- return macAll;
|
|
|
- }
|
|
|
-
|
|
|
- //-------- 获取mac地址--------end
|
|
|
-
|
|
|
- public void showTip(final String tip){
|
|
|
- this.runOnGLThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- String str = "window.AdM.showTip('"+ tip + "');";
|
|
|
- Cocos2dxJavascriptJavaBridge.evalString(str);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- public void AccessTokenCallToJs(final String code){
|
|
|
- this.runOnGLThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- String str = "window.AdM.onGetAccessCode('"+ code + "');";
|
|
|
- Cocos2dxJavascriptJavaBridge.evalString(str);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- public void updateMachine(final String android_id,final String idfa,final String imei,final String mac,final String oaid,final String umid, final String versionName,
|
|
|
- final String umengChannel, final String deviceType, final String androidVersion, final String UA){
|
|
|
-// android_id, idfa, imei, mac, oaid, umid
|
|
|
- this.runOnGLThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- String str = "window.AdM.updateMachine('"+ android_id +"#" + idfa + "#" + imei + "#" + mac + "#" + oaid + "#" + umid + "#" + BuildConfig.TF_CHANNEL +
|
|
|
- "#" + versionName + "#" + umengChannel + "#" + deviceType + "#" + androidVersion + "#" + UA + "');";
|
|
|
- Cocos2dxJavascriptJavaBridge.evalString(str);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Cocos2dxGLSurfaceView onCreateView() {
|
|
|
- Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
|
|
|
- // TestCpp should create stencil buffer
|
|
|
- glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);
|
|
|
- SDKWrapper.getInstance().setGLSurfaceView(glSurfaceView, this);
|
|
|
-
|
|
|
- return glSurfaceView;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onResume() {
|
|
|
- super.onResume();
|
|
|
- SDKWrapper.getInstance().onResume();
|
|
|
- TTAdManagerHolder.freshApkState();
|
|
|
-
|
|
|
- if(playTimeStart == 0){
|
|
|
- playTimeStart = getSecondTimestampTwo(new Date());
|
|
|
- }
|
|
|
- Log.d("test>>> ", "onResume: playTimeStart " + playTimeStart);
|
|
|
-
|
|
|
- if(SwitchManager.ksSDKSwitch){
|
|
|
- if(BuildConfig.TF_CHANNEL.equals("2") && isTurboInit){
|
|
|
- TurboAgent.onPageResume(this);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(canShowSlash == 1){
|
|
|
- int now = getSecondTimestampTwo(new Date());
|
|
|
- end_duration = now - duration;
|
|
|
- Log.d("test>>> onResume ", "end_duration: "+end_duration);
|
|
|
- if(duration != 0 && end_duration >= 60){
|
|
|
- this.showSplash();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(BuildConfig.TF_CHANNEL.equals("3")){
|
|
|
- GDTAction.logAction(ActionType.START_APP);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onPause() {
|
|
|
- super.onPause();
|
|
|
- SDKWrapper.getInstance().onPause();
|
|
|
- if(SwitchManager.ksSDKSwitch){
|
|
|
- if(BuildConfig.TF_CHANNEL.equals("2") && isTurboInit){
|
|
|
- TurboAgent.onPagePause(this);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onDestroy() {
|
|
|
- super.onDestroy();
|
|
|
-
|
|
|
- // Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508
|
|
|
- if (!isTaskRoot()) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- SDKWrapper.getInstance().onDestroy();
|
|
|
-
|
|
|
- wakeUpAdapter = null;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
- super.onActivityResult(requestCode, resultCode, data);
|
|
|
- SDKWrapper.getInstance().onActivityResult(requestCode, resultCode, data);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onNewIntent(Intent intent) {
|
|
|
- super.onNewIntent(intent);
|
|
|
- SDKWrapper.getInstance().onNewIntent(intent);
|
|
|
-// 此处要调用,否则App在后台运行时,会无法截获
|
|
|
- OpenInstall.getWakeUp(intent, wakeUpAdapter);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onRestart() {
|
|
|
- super.onRestart();
|
|
|
- SDKWrapper.getInstance().onRestart();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onStop() {
|
|
|
- super.onStop();
|
|
|
- SDKWrapper.getInstance().onStop();
|
|
|
-
|
|
|
- playTimeEnd = getSecondTimestampTwo(new Date());
|
|
|
- final int playTime = playTimeEnd - playTimeStart;
|
|
|
- Log.d("test>>> ", "onStop: playTime " + playTime);
|
|
|
- playTimeStart = 0;
|
|
|
-
|
|
|
- if(playTime > 0){
|
|
|
- this.runOnGLThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- String str = "window.AdM.updateActivateLog("+ playTime + ");";
|
|
|
- Cocos2dxJavascriptJavaBridge.evalString(str);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- duration = getSecondTimestampTwo(new Date());
|
|
|
- Log.d("test>>> ", "onStop: " + duration);
|
|
|
-
|
|
|
- if(!Util.isForeground(this))
|
|
|
- {
|
|
|
- Util.isActive = false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onBackPressed() {
|
|
|
- SDKWrapper.getInstance().onBackPressed();
|
|
|
- super.onBackPressed();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onConfigurationChanged(Configuration newConfig) {
|
|
|
- SDKWrapper.getInstance().onConfigurationChanged(newConfig);
|
|
|
- super.onConfigurationChanged(newConfig);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
- SDKWrapper.getInstance().onRestoreInstanceState(savedInstanceState);
|
|
|
- super.onRestoreInstanceState(savedInstanceState);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onSaveInstanceState(Bundle outState) {
|
|
|
- SDKWrapper.getInstance().onSaveInstanceState(outState);
|
|
|
- super.onSaveInstanceState(outState);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onStart() {
|
|
|
- SDKWrapper.getInstance().onStart();
|
|
|
- super.onStart();
|
|
|
- }
|
|
|
-
|
|
|
- public void checkPermission() {
|
|
|
- String[] arr;
|
|
|
- if(BuildConfig.TF_CHANNEL.equals("3")){
|
|
|
- arr = new String[]{Manifest.permission.READ_PHONE_STATE,
|
|
|
- Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
- Manifest.permission.ACCESS_COARSE_LOCATION,
|
|
|
- Manifest.permission.ACCESS_FINE_LOCATION};
|
|
|
- }
|
|
|
- else{
|
|
|
- arr = new String[]{Manifest.permission.READ_PHONE_STATE,
|
|
|
- Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
|
|
- }
|
|
|
-
|
|
|
- boolean has = false;
|
|
|
- for (String x: arr) {
|
|
|
- int permissionCheck = ContextCompat.checkSelfPermission(this, x);
|
|
|
- if(permissionCheck != PackageManager.PERMISSION_GRANTED){
|
|
|
- has = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(has){
|
|
|
- ActivityCompat.requestPermissions(this, arr, this.PERMISSIONS_REQUEST_STORAGE);
|
|
|
- }
|
|
|
- else{
|
|
|
- Log.d("vvvvvvvvv", "checkPermission");
|
|
|
- startUpdatMachine();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
|
|
- for (int i = 0; i < grantResults.length; i++) {
|
|
|
- if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
|
|
|
- Toast toast = Toast.makeText(getApplicationContext(), "没有该权限,此应用程序可能无法正常工作。打开应用设置屏幕以修改应用权限", Toast.LENGTH_LONG);
|
|
|
- toast.setGravity(Gravity.TOP,0,0);
|
|
|
- toast.show();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Log.d("vvvvvvvvv", "onRequestPermissionsResult ");
|
|
|
- startUpdatMachine();
|
|
|
- }
|
|
|
-
|
|
|
- @SuppressLint({"MissingPermission", "HardwareIds"})
|
|
|
- public static String getImei(Context context) {
|
|
|
- String imei = "";
|
|
|
- try {
|
|
|
- TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
- imei = tm.getDeviceId();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return imei;
|
|
|
- }
|
|
|
-
|
|
|
- public void initKs(){
|
|
|
- if(!SwitchManager.ksSDKSwitch){
|
|
|
- return;
|
|
|
- }
|
|
|
- if(BuildConfig.TF_CHANNEL.equals("2")){
|
|
|
- if(!isTurboInit){
|
|
|
- isTurboInit = true;
|
|
|
- //快手检测
|
|
|
- TurboAgent.init(TurboConfig.TurboConfigBuilder.create(this)
|
|
|
- .setAppId(BuildConfig.KS_AID)
|
|
|
- .setAppName(BuildConfig.KS_ANAME)
|
|
|
- .setAppChannel(BuildConfig.KS_CHANNEL)
|
|
|
- .setEnableDebug(false)
|
|
|
- .build());
|
|
|
-
|
|
|
- //1.活跃事件,进入app首页时调用
|
|
|
- TurboAgent.onAppActive();
|
|
|
- Log.d("aaaaaaaaaaa ", "initKs: ");
|
|
|
-
|
|
|
-// TurboAgent.registerOAIDListener(this, new OAIDListener() {
|
|
|
-// @Override
|
|
|
-// public void OnOAIDValid(String oaid) {
|
|
|
-// //2.OnOAIDValid可能在任意线程返回,请勿做磁盘缓存
|
|
|
-// mOAID = oaid;
|
|
|
-//
|
|
|
-// TurboAgent.unRegisterOAIDListener();
|
|
|
-// }
|
|
|
-// });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void regToWx() {
|
|
|
- Log.d("HHHHHHH", "regToWx ");
|
|
|
- String APP_ID = BuildConfig.WX_APP_ID;
|
|
|
- api = WXAPIFactory.createWXAPI(this, APP_ID, false);
|
|
|
- api.registerApp(APP_ID);
|
|
|
-// checkPermission();
|
|
|
- }
|
|
|
-
|
|
|
- public void startWxAuth() {
|
|
|
- Log.d("HHHHHHH", "startWxAuth ");
|
|
|
- if (!api.isWXAppInstalled()) {
|
|
|
- Toast.makeText(AppActivity.this, "您的设备未安装微信客户端", Toast.LENGTH_SHORT).show();
|
|
|
- } else {
|
|
|
- final SendAuth.Req req = new SendAuth.Req();
|
|
|
- req.scope = "snsapi_userinfo";
|
|
|
- req.state = "wechat_sdk_demo_test";
|
|
|
- api.sendReq(req);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void sharePic(){
|
|
|
- Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.splash_icon);
|
|
|
- WXImageObject imgObj = new WXImageObject(bmp);
|
|
|
-
|
|
|
- WXMediaMessage msg = new WXMediaMessage();
|
|
|
- msg.mediaObject = imgObj;
|
|
|
-
|
|
|
- Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 90, 200, true);
|
|
|
- bmp.recycle();
|
|
|
- msg.thumbData = bmpToByteArray(thumbBmp, true);
|
|
|
-
|
|
|
- SendMessageToWX.Req req = new SendMessageToWX.Req();
|
|
|
- req.transaction = buildTransaction("img");
|
|
|
- req.message = msg;
|
|
|
- req.scene = SendMessageToWX.Req.WXSceneSession;
|
|
|
- api.sendReq(req);
|
|
|
-
|
|
|
-// Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.share);
|
|
|
-// Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 90, 200, true);
|
|
|
-// bmp.recycle();
|
|
|
-//
|
|
|
-// WXMiniProgramObject miniProgramObj = new WXMiniProgramObject();
|
|
|
-// miniProgramObj.webpageUrl = "http://www.qq.com"; // 兼容低版本的网页链接
|
|
|
-// miniProgramObj.miniprogramType = WXMiniProgramObject.MINIPROGRAM_TYPE_PREVIEW;// 正式版:0,测试版:1,体验版:2
|
|
|
-// miniProgramObj.userName = "gh_0b100a4eebbb"; // 小程序原始id
|
|
|
-// miniProgramObj.path = "/pages/index"; //小程序页面路径;对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"
|
|
|
-// WXMediaMessage msg = new WXMediaMessage(miniProgramObj);
|
|
|
-// msg.title = "小程序消息Title"; // 小程序消息title
|
|
|
-// msg.description = "小程序消息Desc"; // 小程序消息desc
|
|
|
-// msg.thumbData = Util.bmpToByteArray(thumbBmp, true);; // 小程序消息封面图片,小于128k
|
|
|
-//
|
|
|
-// SendMessageToWX.Req req = new SendMessageToWX.Req();
|
|
|
-// req.transaction = buildTransaction("miniProgram");
|
|
|
-// req.message = msg;
|
|
|
-// req.scene = SendMessageToWX.Req.WXSceneSession; // 目前只支持会话
|
|
|
-// api.sendReq(req);
|
|
|
- Log.d("PPPPP", "sharePic end ");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 图片url转bitmap
|
|
|
- */
|
|
|
- public static Bitmap getBitMBitmap(String urlpath) {
|
|
|
- Bitmap map = null;
|
|
|
- try {
|
|
|
- URL url = new URL(urlpath);
|
|
|
- URLConnection conn = url.openConnection();
|
|
|
- conn.connect();
|
|
|
- InputStream in;
|
|
|
- in = conn.getInputStream();
|
|
|
- map = BitmapFactory.decodeStream(in);
|
|
|
- // TODO Auto-generated catch block
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 网页分享
|
|
|
- * @param url 地址
|
|
|
- * @param title 标题
|
|
|
- * @param description 描述
|
|
|
- * @param judge 类型选择 好友-WECHAT_FRIEND 朋友圈-WECHAT_MOMENT
|
|
|
- */
|
|
|
- public void WxUrlShare(String url,String title,String description,String imgUrl,int judge){
|
|
|
-// title = "testtitle";
|
|
|
-// description = "testdesc";
|
|
|
- Bitmap bitmap = getBitMBitmap(imgUrl);
|
|
|
- WXWebpageObject wxWebpageObject = new WXWebpageObject();
|
|
|
- wxWebpageObject.webpageUrl = url;
|
|
|
-
|
|
|
- WXMediaMessage wxMediaMessage = new WXMediaMessage(wxWebpageObject);
|
|
|
- wxMediaMessage.title = title;
|
|
|
- wxMediaMessage.description = description;
|
|
|
- Bitmap thunmpBmp = Bitmap.createScaledBitmap(bitmap,100,100,true);
|
|
|
- bitmap.recycle();
|
|
|
- wxMediaMessage.thumbData = bmpToByteArray(thunmpBmp,true);
|
|
|
-
|
|
|
- SendMessageToWX.Req req = new SendMessageToWX.Req();
|
|
|
- req.transaction ="webpage"+String.valueOf(System.currentTimeMillis());
|
|
|
- req.message = wxMediaMessage;
|
|
|
- req.scene = SendMessageToWX.Req.WXSceneSession;
|
|
|
- api.sendReq(req);
|
|
|
- }
|
|
|
-
|
|
|
- private String buildTransaction(final String type) {
|
|
|
- return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis();
|
|
|
- }
|
|
|
-
|
|
|
- public void setClipboard(final String str){
|
|
|
- this.runOnUiThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- //获取剪贴板管理器:
|
|
|
- ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
- // 创建普通字符型ClipData
|
|
|
- ClipData mClipData = ClipData.newPlainText("Label", str);
|
|
|
- // 将ClipData内容放到系统剪贴板里。
|
|
|
- cm.setPrimaryClip(mClipData);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- //定义是否退出程序的标记
|
|
|
- private int popTotal = 0;
|
|
|
- private boolean isExit = false;
|
|
|
- //定义接受用户发送信息的handler
|
|
|
- private Handler mHandler = new Handler() {
|
|
|
- @Override
|
|
|
- public void handleMessage(Message msg) {
|
|
|
- super.handleMessage(msg);
|
|
|
- //标记用户不退出状态
|
|
|
- popTotal = 0;
|
|
|
- isExit = false;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- public void popChange(int popNum){
|
|
|
- if(popNum > 0){
|
|
|
- isExit = false;
|
|
|
- }
|
|
|
- popTotal += popNum;
|
|
|
- if(popTotal < 0){
|
|
|
- popTotal = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
- switch (keyCode) {
|
|
|
- case KeyEvent.KEYCODE_BACK:
|
|
|
- if(popTotal > 0){
|
|
|
- popTotal--;
|
|
|
- closePanelFromHome();
|
|
|
- }
|
|
|
- else{
|
|
|
- //如果isExit标记为false,提示用户再次按键
|
|
|
- if (!isExit) {
|
|
|
- isExit = true;
|
|
|
- openDailyPanel();
|
|
|
- Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
|
|
|
- //如果用户没有在2秒内再次按返回键的话,就发送消息标记用户为不退出状态
|
|
|
- mHandler.sendEmptyMessageDelayed(0, 3000);
|
|
|
- }
|
|
|
- //如果isExit标记为true,退出程序
|
|
|
- else {
|
|
|
- //退出程序
|
|
|
- finish();
|
|
|
- System.exit(0);
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- private void closePanelFromHome(){
|
|
|
- this.runOnGLThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- Cocos2dxJavascriptJavaBridge.evalString("window.AdM.closePanelFromHome();");
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void openDailyPanel(){
|
|
|
- this.runOnGLThread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- Cocos2dxJavascriptJavaBridge.evalString("window.AdM.openDailyPanel();");
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- public void sendSuperRole(String commonStr){
|
|
|
- String[] commonStrArr = commonStr.split(";");
|
|
|
- try {
|
|
|
- JSONObject superProperties = new JSONObject();
|
|
|
- superProperties.put("buy_num", Integer.parseInt(commonStrArr[0]));
|
|
|
- superProperties.put("role_name", commonStrArr[1]);
|
|
|
- superProperties.put("app_version", commonStrArr[2]);
|
|
|
- superProperties.put("video_total", Integer.parseInt(commonStrArr[3]));
|
|
|
- superProperties.put("current_redmoney_stock", Integer.parseInt(commonStrArr[4]));
|
|
|
- superProperties.put("current_gold_stock", commonStrArr[5]);
|
|
|
- superProperties.put("monster_max_level", Integer.parseInt(commonStrArr[6]));
|
|
|
- superProperties.put("logindays_total", Integer.parseInt(commonStrArr[7]));
|
|
|
- superProperties.put("current_giftStone_stock", Integer.parseInt(commonStrArr[8]));
|
|
|
- superProperties.put("gift_1", Integer.parseInt(commonStrArr[9]));
|
|
|
- superProperties.put("gift_2", Integer.parseInt(commonStrArr[10]));
|
|
|
- superProperties.put("gift_3", Integer.parseInt(commonStrArr[11]));
|
|
|
- superProperties.put("gift_4", Integer.parseInt(commonStrArr[12]));
|
|
|
- superProperties.put("gift_5", Integer.parseInt(commonStrArr[13]));
|
|
|
- superProperties.put("gift_6", Integer.parseInt(commonStrArr[14]));
|
|
|
- superProperties.put("gift_7", Integer.parseInt(commonStrArr[15]));
|
|
|
- superProperties.put("gift_8", Integer.parseInt(commonStrArr[16]));
|
|
|
- superProperties.put("gift_9", Integer.parseInt(commonStrArr[17]));
|
|
|
- superProperties.put("gift_10", Integer.parseInt(commonStrArr[18]));
|
|
|
- superProperties.put("gift_11", Integer.parseInt(commonStrArr[19]));
|
|
|
- superProperties.put("gift_12", Integer.parseInt(commonStrArr[20]));
|
|
|
- superProperties.put("gift_13", Integer.parseInt(commonStrArr[21]));
|
|
|
- superProperties.put("gift_14", Integer.parseInt(commonStrArr[22]));
|
|
|
- superProperties.put("turntable_total", Integer.parseInt(commonStrArr[23]));
|
|
|
- superProperties.put("shop_total", Integer.parseInt(commonStrArr[24]));
|
|
|
- superProperties.put("invest_total", Integer.parseInt(commonStrArr[25]));
|
|
|
- superProperties.put("treasure_total", Integer.parseInt(commonStrArr[26]));
|
|
|
- superProperties.put("airship_total", Integer.parseInt(commonStrArr[27]));
|
|
|
- TAinstance.user_set(superProperties);
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void setTAEventRegister(){
|
|
|
- Log.d("setTAEvent ", "setTAEventRegister: ");
|
|
|
- String cTime = curTime();
|
|
|
-
|
|
|
- try {
|
|
|
- JSONObject properties = new JSONObject();
|
|
|
- properties.put("final_login_time", cTime);
|
|
|
- TAinstance.user_set(properties);
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- JSONObject properties = new JSONObject();
|
|
|
- properties.put("RegTime", cTime);
|
|
|
- properties.put("channel_id", BuildConfig.UM_CHANNEL);
|
|
|
- TAinstance.user_setOnce(properties);
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void setTAAccount(){
|
|
|
- try {
|
|
|
- JSONObject properties = new JSONObject();
|
|
|
- properties.put("account", userID);
|
|
|
- TAinstance.user_setOnce(properties);
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void setTADeviceID(String deviceID){
|
|
|
- try {
|
|
|
- JSONObject properties = new JSONObject();
|
|
|
- properties.put("device_id", deviceID);
|
|
|
- TAinstance.user_setOnce(properties);
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private String curTime(){
|
|
|
- String pattern = "yyyy-MM-dd HH:mm:ss.SSS";
|
|
|
- SimpleDateFormat sDateFormat = new SimpleDateFormat(pattern, Locale.CHINA);
|
|
|
- String timeString = sDateFormat.format(new Date());
|
|
|
-
|
|
|
- Log.d("TAEvent", "setTAEventUser: "+timeString);
|
|
|
- return timeString;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置人物属性
|
|
|
- * @param type 0 set 1 add
|
|
|
- * @param property 属性名
|
|
|
- * @param value 数值
|
|
|
- */
|
|
|
- public void setTAEventUser(int type, String property, float value){
|
|
|
- if(type == 0){
|
|
|
- try {
|
|
|
- JSONObject properties = new JSONObject();
|
|
|
- properties.put(property,value);
|
|
|
- TAinstance.user_set(properties);
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- else{
|
|
|
- try {
|
|
|
- JSONObject properties = new JSONObject();
|
|
|
- properties.put(property,value);
|
|
|
- TAinstance.user_add(properties);
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void setTAEvent(String taEventID, String eventID, String des){
|
|
|
- try {
|
|
|
- JSONObject properties = new JSONObject();
|
|
|
- properties.put(eventID, des);
|
|
|
- TAinstance.track(taEventID, properties);
|
|
|
- Log.d("setTAEvent ", "setTAEvent: "+eventID);
|
|
|
- } catch (JSONException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void showSplash(){
|
|
|
- startActivity(new Intent(this, SplashAdShowActivity.class));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取精确到秒的时间戳
|
|
|
- *
|
|
|
- * @param date
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static int getSecondTimestampTwo(Date date) {
|
|
|
- if (null == date) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- String timestamp = String.valueOf(date.getTime() / 1000);
|
|
|
- return Integer.valueOf(timestamp);
|
|
|
- }
|
|
|
- public String getInviteCode(){
|
|
|
- OpenInstall.getInstall(new AppInstallAdapter() {
|
|
|
- @Override
|
|
|
- public void onInstall(AppData appData) {
|
|
|
- //获取渠道数据
|
|
|
- String channelCode = appData.getChannel();
|
|
|
- //获取自定义数据
|
|
|
- String bindData = appData.getData();
|
|
|
- Log.d("getInviteCode", "bindData:" + bindData);
|
|
|
-
|
|
|
-
|
|
|
- TTAdManagerHolder.InviteCodeCallToJs(bindData);
|
|
|
- Log.d("getInviteCode", "getInstall : installData = " + appData.toString());
|
|
|
- }
|
|
|
- });
|
|
|
- return "";
|
|
|
- }
|
|
|
- public void registerMainInstance(){
|
|
|
- new ContextWrapperUtil(getContext(), BuildConfig.APPLICATION_ID);
|
|
|
- api = WXAPIFactory.createWXAPI(this, BuildConfig.WX_APP_ID, true);
|
|
|
- api.registerApp(BuildConfig.WX_APP_ID);
|
|
|
- }
|
|
|
- public List<String> addPkg(){
|
|
|
- Map<String, String> map = new HashMap<String,String>();
|
|
|
- map.put("wx64f9cf5b17af074d", "com.tencent.mtt");
|
|
|
- map.put("wx020a535dccd46c11","com.UCMobile");
|
|
|
- map.put("wx2fab8a9063c8c6d0","com.qiyi.video");
|
|
|
- map.put("wxe386966df7b712ca","com.suning.mobile.ebuy");
|
|
|
- map.put("wx50d801314d9eb858","com.ss.android.article.news");
|
|
|
- map.put("wx8561ba2beb9f65e2","com.snda.wifilocating");
|
|
|
- map.put("wxc2ff198ba4a63f06","com.ijinshan.browser_fast");
|
|
|
- map.put("wx073f4a4daff0abe8","com.tencent.news");
|
|
|
- String appInfo = "";
|
|
|
- Set<String> keySet = map.keySet();
|
|
|
- //遍历存放所有key的Set集合
|
|
|
- Iterator<String> it =keySet.iterator();
|
|
|
- List l = new ArrayList();
|
|
|
- while(it.hasNext()){ //利用了Iterator迭代器**
|
|
|
- //得到每一个key
|
|
|
- String key = it.next();
|
|
|
- //通过key获取对应的value
|
|
|
- String value = map.get(key);
|
|
|
-// System.out.println(key+"="+value);
|
|
|
- boolean isSave = true;
|
|
|
- try {
|
|
|
- PackageManager pm = getPackageManager();
|
|
|
- pm.getPackageInfo(value, PackageManager.GET_ACTIVITIES);
|
|
|
- } catch (PackageManager.NameNotFoundException e) {
|
|
|
-// e.printStackTrace();
|
|
|
- isSave = false;
|
|
|
- }
|
|
|
- if(isSave){
|
|
|
- l.add(key);
|
|
|
- l.add(value);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- return l;
|
|
|
- }
|
|
|
- public void createNewInstance(){
|
|
|
- //读取properties文件的方法
|
|
|
-// Log.v("createNewInstance","createNewInstance();");
|
|
|
-
|
|
|
- String app_id = BuildConfig.WX_APP_ID;
|
|
|
- String pkg = BuildConfig.APPLICATION_ID;
|
|
|
- List<String> l = addPkg();
|
|
|
- if(l.size() == 2){
|
|
|
- app_id = l.get(0);
|
|
|
- pkg = l.get(1);
|
|
|
- }
|
|
|
-// Log.v("createNewInstance","createNewInstance info"+info);
|
|
|
-
|
|
|
- IWXAPI createWXAPI = WXAPIFactory.createWXAPI(new ContextWrapperUtil(this, pkg), app_id, true);
|
|
|
- api = createWXAPI;
|
|
|
- api.registerApp(app_id);
|
|
|
- }
|
|
|
- /**
|
|
|
- * fileName:String apk完整路径
|
|
|
- * */
|
|
|
- public void installApk(String fileName){
|
|
|
- Log.v("installApk","start");
|
|
|
- File apk = new File(fileName);
|
|
|
- Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
|
|
|
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
- Uri uri = FileProvider.getUriForFile(this, getPackageName()+".com.testDownLoad.fileprovider", apk);
|
|
|
- intent.setDataAndType(uri, "application/vnd.android.package-archive");
|
|
|
- }else{
|
|
|
- intent.setDataAndType(Uri.fromFile(apk),"application/vnd.android.package-archive");
|
|
|
- }
|
|
|
- try {
|
|
|
- startActivity(intent);
|
|
|
- }catch(Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- public boolean checkStartApp(String pkg, boolean start){
|
|
|
- PackageManager packageManager = getPackageManager();
|
|
|
- Intent intent=new Intent();
|
|
|
- intent.setPackage(null); // 加上这句代码
|
|
|
- intent =packageManager.getLaunchIntentForPackage(pkg);
|
|
|
- if(intent==null){
|
|
|
- return false;
|
|
|
- }else{
|
|
|
- if(start){
|
|
|
- startActivity(intent);
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|