| | |
| | | |
| | | import androidx.multidex.MultiDex; |
| | | |
| | | import com.google.android.gms.common.ConnectionResult; |
| | | import com.google.android.gms.common.GoogleApiAvailability; |
| | | import com.google.firebase.messaging.FirebaseMessaging; |
| | | import com.google.gson.Gson; |
| | | import com.hdl.hdlhttp.HxHttpConfig; |
| | | import com.hdl.linkpm.sdk.HDLLinkPMSdk; |
| | |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.enums.Languages; |
| | | import com.hdl.photovoltaic.enums.LogoutType; |
| | | import com.hdl.photovoltaic.enums.LowerTagType; |
| | | import com.hdl.photovoltaic.enums.NetworkType; |
| | |
| | | import com.hdl.photovoltaic.ui.StartActivity; |
| | | import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; |
| | | import com.hdl.photovoltaic.utils.AppManagerUtils; |
| | | import com.hdl.photovoltaic.utils.BadgeUtils; |
| | | import com.hdl.photovoltaic.utils.LocalManageUtil; |
| | | import com.hdl.photovoltaic.utils.NetworkUtils; |
| | | import com.hdl.photovoltaic.utils.SharedPreUtils; |
| | |
| | | |
| | | // // 获取当前进程的PID |
| | | // String processMessage = "进程Uid:" + Process.myUid() + "进程ID:" + Process.myPid() + " 进程名:" + RuningAcitvityUtil.getAppName(getBaseContext()); |
| | | // Log.d("=======", processMessage); |
| | | Log.d("Application==onCreate", "onCreate"); |
| | | // Log.d(TAG, processMessage); |
| | | // if (RuningAcitvityUtil.getAppName(getBaseContext()).contains(":")) { |
| | | // //非原生进程,用初始化后面的 |
| | |
| | | SharedPreUtils.init(this); |
| | | getAppLanguage(); |
| | | //预创建脚本json文件夹 |
| | | HdlFileLogic.getInstance().createHdlESLocalJsonDirectory(); |
| | | HdlFileLogic.getInstance().createHdlDeviceModelLocalJsonDirectory(); |
| | | init(); |
| | | |
| | | |
| | |
| | | if (TextUtils.isEmpty(language)) { |
| | | //从内存里面获取不到语言,获取当前系统的; |
| | | String str = getResources().getConfiguration().locale.getLanguage(); |
| | | if (str.equals(LocalManageUtil.zh)) { |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.zh); |
| | | if (str.equals(Languages.zh)) { |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(Languages.zh); |
| | | } else if (str.equals(Languages.ar)) { |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(Languages.ar); |
| | | } else { |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.en); |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(Languages.en); |
| | | } |
| | | } |
| | | } |
| | |
| | | initAutoSize(); |
| | | // //初始化极光推送 |
| | | // initJPush(); |
| | | //谷歌原生fcm推送 |
| | | // 检查 Google Play Services 后再初始化 FCM |
| | | if (isGooglePlayServicesAvailable(this)) { |
| | | initFCM(); |
| | | } else { |
| | | HdlLogLogic.print("Google Play Services 不可用,无法使用 FCM", true); |
| | | // 可以在这里初始化备选推送方案(如阿里云自建通道) |
| | | } |
| | | initHDLLinkPMSdk(); |
| | | HDLLinkLocalSdk.getInstance().init(getInstance()); |
| | | initSocket(); |
| | |
| | | * 初始化HDLLinkPMSdk |
| | | */ |
| | | private void initHDLLinkPMSdk() { |
| | | Log.d("===1====", "2222222"); |
| | | //1.初始化SDK |
| | | HDLLinkPMSdk.initWithAppKey(this, AppConfigManage.getAppKey(), AppConfigManage.getAppSecret(), AppConfigManage.getAPPRegionUrl()); |
| | | //2.设置打印 |
| | |
| | | |
| | | if (TextUtils.isEmpty(UserConfigManage.getInstance().getCurrentAppLanguage())) { |
| | | //默认配置接口请求语言是英文 |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(LocalManageUtil.en); |
| | | UserConfigManage.getInstance().setCurrentAppLanguage(Languages.en); |
| | | } |
| | | //3.配置接口请求语言 |
| | | HDLLinkPMSdk.setLanguage(UserConfigManage.getInstance().getCurrentAppLanguage()); |
| | |
| | | new Handler().postDelayed(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | BadgeUtils.cancelAllNotifications(getApplicationContext()); |
| | | BadgeUtils.clearBadge(getApplicationContext()); |
| | | //切换服务器地址用的 |
| | | UserConfigManage.getInstance().setOnlineServer(!UserConfigManage.getInstance().isOnlineServer()); |
| | | UserConfigManage.getInstance().Save(); |
| | |
| | | new Handler().postDelayed(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | BadgeUtils.cancelAllNotifications(getApplicationContext()); |
| | | BadgeUtils.clearBadge(getApplicationContext()); |
| | | restartApp(mHDLApp); |
| | | } |
| | | }, 500); |
| | |
| | | } |
| | | SystemClock.sleep(200); |
| | | initDCUniMPSDK(); |
| | | BadgeUtils.cancelAllNotifications(getApplicationContext()); |
| | | BadgeUtils.clearBadge(getApplicationContext()); |
| | | Intent intent = new Intent(getInstance(), LoginActivity.class); |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| | | startActivity(intent); |
| | |
| | | } |
| | | SystemClock.sleep(200); |
| | | initDCUniMPSDK(); |
| | | BadgeUtils.cancelAllNotifications(getApplicationContext()); |
| | | BadgeUtils.clearBadge(getApplicationContext()); |
| | | Intent intent = new Intent(getInstance(), LoginActivity.class); |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| | | if (type == 1) { |
| | |
| | | // JPushInterface.init(getBaseContext()); |
| | | } |
| | | |
| | | private void initFCM() { |
| | | // 获取 FCM Token |
| | | FirebaseMessaging.getInstance().getToken() |
| | | .addOnCompleteListener(task -> { |
| | | if (!task.isSuccessful()) { |
| | | Log.w("FCM", "获取 FCM Token 失败", task.getException()); |
| | | return; |
| | | } |
| | | // 获取新的 FCM Token |
| | | String token = task.getResult(); |
| | | Log.d("FCM", "FCM Token: " + token); |
| | | |
| | | // 保存 token |
| | | saveFCMToken(token); |
| | | }); |
| | | |
| | | // // 订阅主题(可选) |
| | | // FirebaseMessaging.getInstance().subscribeToTopic("all_users") |
| | | // .addOnCompleteListener(task -> { |
| | | // String msg = "订阅主题成功"; |
| | | // if (!task.isSuccessful()) { |
| | | // msg = "订阅主题失败"; |
| | | // } |
| | | // Log.d("FCM", msg); |
| | | // }); |
| | | } |
| | | |
| | | /** |
| | | * 检查 Google Play Services 是否可用 |
| | | */ |
| | | private boolean isGooglePlayServicesAvailable(Context context) { |
| | | GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); |
| | | int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context); |
| | | return resultCode == ConnectionResult.SUCCESS; |
| | | } |
| | | |
| | | /** |
| | | * 保存令牌 |
| | | * |
| | | * @param token 令牌 |
| | | */ |
| | | public void saveFCMToken(String token) { |
| | | if (TextUtils.isEmpty(token.trim())) { |
| | | return; |
| | | } |
| | | UserConfigManage.getInstance().setPushToken(token); |
| | | UserConfigManage.getInstance().Save(); |
| | | |
| | | // // 发送到服务器 |
| | | // sendTokenToServer(token); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 监听网络状态变化 |
| | | */ |