feat:屏蔽启动页隐私政策弹窗;
feat:去掉我的(实名认证、青少年、客服中心)入口 feat:去掉设置-绑定支付宝入口
This commit is contained in:
@@ -636,7 +636,7 @@ public class MainActivity extends BaseMvpActivity<IMainView, MainPresenter>
|
||||
@SuppressLint("CheckResult")
|
||||
private void firstLoadedUserInfo() {
|
||||
//青少年弹窗处理
|
||||
PmDialogShowMrg.get().handle(new WeakReference<>(this));
|
||||
// PmDialogShowMrg.get().handle(new WeakReference<>(this));
|
||||
|
||||
//通知栏权限判断
|
||||
NoticationsUiHelper.handle(this, getDialogManager());
|
||||
|
@@ -433,14 +433,14 @@ class MeFragment : BaseFragment(), View.OnClickListener {
|
||||
"usercenter_nugift_pop_click"
|
||||
)
|
||||
}
|
||||
R.id.ll_pm_mode, R.id.tv_me_youth_mode -> PatriarchModeActivity.start(mContext)
|
||||
R.id.tv_me_real_name -> CommonWebViewActivity.start(
|
||||
mContext,
|
||||
UriProvider.getTutuRealNamePage()
|
||||
)
|
||||
R.id.tv_me_service -> {
|
||||
CustomerServerHelper.contactCustomerServer(mContext)
|
||||
}
|
||||
// R.id.ll_pm_mode, R.id.tv_me_youth_mode -> PatriarchModeActivity.start(mContext)
|
||||
// R.id.tv_me_real_name -> CommonWebViewActivity.start(
|
||||
// mContext,
|
||||
// UriProvider.getTutuRealNamePage()
|
||||
// )
|
||||
// R.id.tv_me_service -> {
|
||||
// CustomerServerHelper.contactCustomerServer(mContext)
|
||||
// }
|
||||
R.id.tv_user_id -> {
|
||||
mUserInfo?.let {
|
||||
ClipboardUtil.clipboardCopyText(it.erbanNo.toString())
|
||||
|
@@ -13,6 +13,7 @@ import androidx.databinding.DataBindingUtil;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.netease.nim.uikit.StatusBarUtil;
|
||||
import com.netease.nim.uikit.support.glide.GlideApp;
|
||||
import com.nnbc123.library.common.util.DeviceUtil;
|
||||
import com.umeng.commonsdk.UMConfigure;
|
||||
import com.nnbc123.app.MainActivity;
|
||||
import com.nnbc123.app.NimMiddleActivity;
|
||||
@@ -20,7 +21,6 @@ import com.nnbc123.app.R;
|
||||
import com.nnbc123.app.application.XChatApplication;
|
||||
import com.nnbc123.app.databinding.ActivitySplashBinding;
|
||||
import com.nnbc123.app.other.SplashBitmapTransformation;
|
||||
import com.nnbc123.app.other.dialog.PrivacyAgreementDialog;
|
||||
import com.nnbc123.core.channel_page.model.ChannelPageModel;
|
||||
import com.nnbc123.core.initial.InitialModel;
|
||||
import com.nnbc123.core.initial.SplashComponent;
|
||||
@@ -31,7 +31,7 @@ import com.nnbc123.core.utils.SharedPreferenceUtils;
|
||||
* @author xiaoyu
|
||||
* @date 2017/12/30
|
||||
*/
|
||||
public class SplashActivity extends AppCompatActivity implements View.OnClickListener, PrivacyAgreementDialog.OnCallBack {
|
||||
public class SplashActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
public static final String SHOW_PRIVACY_AGREEMENT = "show_privacy_agreement";
|
||||
private static final int COUNT_DOWN_TIME = 3;
|
||||
@@ -71,30 +71,21 @@ public class SplashActivity extends AppCompatActivity implements View.OnClickLis
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
protected void initiate() {
|
||||
checkPrivacyAgreement();
|
||||
}
|
||||
|
||||
|
||||
private void checkPrivacyAgreement() {
|
||||
boolean isShowPrivacyAgreement = (boolean) SharedPreferenceUtils.get(SHOW_PRIVACY_AGREEMENT, true);
|
||||
if (isShowPrivacyAgreement) {
|
||||
PrivacyAgreementDialog privacyAgreementDialog = new PrivacyAgreementDialog(this);
|
||||
privacyAgreementDialog.setCancelable(false);
|
||||
privacyAgreementDialog.setCanceledOnTouchOutside(false);
|
||||
privacyAgreementDialog.setOnCallBack(this);
|
||||
privacyAgreementDialog.show();
|
||||
SharedPreferenceUtils.put(SHOW_PRIVACY_AGREEMENT, false);
|
||||
XChatApplication.initOtherSDK();
|
||||
showSplash(true);
|
||||
} else {
|
||||
showSplash(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void showSplash(boolean first) {
|
||||
|
||||
UMConfigure.getOaid(this, oaid -> {
|
||||
OaidUtil.setOaid(oaid);
|
||||
if (!TextUtils.isEmpty(DeviceUtil.getAndroidID())) {
|
||||
OaidUtil.setOaid(DeviceUtil.getAndroidID());
|
||||
if (first) ChannelPageModel.get().checkAd();
|
||||
});
|
||||
|
||||
}
|
||||
mBinding.tvSkip.setVisibility(View.VISIBLE);
|
||||
// 不过期的,并且已经下载出来图片的闪屏页数据
|
||||
mLocalSplashVo = InitialModel.get().getLocalSplashVo();
|
||||
@@ -161,16 +152,4 @@ public class SplashActivity extends AppCompatActivity implements View.OnClickLis
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(boolean isConfirm) {
|
||||
if (isConfirm) {
|
||||
SharedPreferenceUtils.put(SHOW_PRIVACY_AGREEMENT, false);
|
||||
XChatApplication.initOtherSDK();
|
||||
showSplash(true);
|
||||
} else {
|
||||
finish();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -93,26 +93,26 @@ public class SettingActivity extends BaseActivity implements View.OnClickListene
|
||||
setPhoneUI("");
|
||||
}
|
||||
});
|
||||
WithdrawModel.get().getWithdrawUserInfo(AuthModel.get().getCurrentUid())
|
||||
.subscribe(withdrawInfo -> {
|
||||
withdrawInfos = withdrawInfo;
|
||||
if (withdrawInfo != null) {
|
||||
if (!TextUtils.isEmpty(withdrawInfo.zxcAccount) && !withdrawInfo.zxcAccount.equals("null")) {
|
||||
setAlipayUI(withdrawInfo.zxcAccount + "(" + withdrawInfo.zxcAccountName + ")");
|
||||
} else {
|
||||
setAlipayUI("");
|
||||
}
|
||||
}
|
||||
});
|
||||
// WithdrawModel.get().getWithdrawUserInfo(AuthModel.get().getCurrentUid())
|
||||
// .subscribe(withdrawInfo -> {
|
||||
// withdrawInfos = withdrawInfo;
|
||||
// if (withdrawInfo != null) {
|
||||
// if (!TextUtils.isEmpty(withdrawInfo.zxcAccount) && !withdrawInfo.zxcAccount.equals("null")) {
|
||||
// setAlipayUI(withdrawInfo.zxcAccount + "(" + withdrawInfo.zxcAccountName + ")");
|
||||
// } else {
|
||||
// setAlipayUI("");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
private void setPhoneUI(String phone) {
|
||||
settingBinding.tvPhone.setText(TextUtils.isEmpty(phone) ? "未绑定" : phone);
|
||||
}
|
||||
|
||||
private void setAlipayUI(String name) {
|
||||
settingBinding.tvAlipay.setText(TextUtils.isEmpty(name) ? "未绑定" : name);
|
||||
}
|
||||
// private void setAlipayUI(String name) {
|
||||
// settingBinding.tvAlipay.setText(TextUtils.isEmpty(name) ? "未绑定" : name);
|
||||
// }
|
||||
|
||||
private void initData() {
|
||||
settingBinding.versions.setText("V" + BasicConfig.getLocalVersionName(getApplicationContext()));
|
||||
@@ -148,21 +148,21 @@ public class SettingActivity extends BaseActivity implements View.OnClickListene
|
||||
}
|
||||
});
|
||||
break;
|
||||
case R.id.rly_alipay_binder://绑定支付宝
|
||||
if (UserModel.get().getCacheLoginUserInfo() == null) {
|
||||
toast("无当前登录用户信息.");
|
||||
return;
|
||||
}
|
||||
if (UserModel.get().getCacheLoginUserInfo().isBindPhone()) {
|
||||
Intent intent = new Intent(getApplicationContext(), BinderAlipayActivity.class);
|
||||
Bundle mBundle = new Bundle();
|
||||
mBundle.putSerializable("withdrawInfo", withdrawInfos);
|
||||
intent.putExtras(mBundle);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
BindPhoneActivity.start(context);
|
||||
}
|
||||
break;
|
||||
// case R.id.rly_alipay_binder://绑定支付宝
|
||||
// if (UserModel.get().getCacheLoginUserInfo() == null) {
|
||||
// toast("无当前登录用户信息.");
|
||||
// return;
|
||||
// }
|
||||
// if (UserModel.get().getCacheLoginUserInfo().isBindPhone()) {
|
||||
// Intent intent = new Intent(getApplicationContext(), BinderAlipayActivity.class);
|
||||
// Bundle mBundle = new Bundle();
|
||||
// mBundle.putSerializable("withdrawInfo", withdrawInfos);
|
||||
// intent.putExtras(mBundle);
|
||||
// startActivity(intent);
|
||||
// } else {
|
||||
// BindPhoneActivity.start(context);
|
||||
// }
|
||||
// break;
|
||||
case R.id.rly_contact_us:
|
||||
UIHelper.openContactUs(this);
|
||||
break;
|
||||
|
@@ -124,47 +124,47 @@
|
||||
android:layout_marginEnd="15dp"
|
||||
android:background="@color/line_353548" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/rly_alipay_binder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:onClick="@{click}">
|
||||
<!-- <RelativeLayout-->
|
||||
<!-- android:id="@+id/rly_alipay_binder"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="50dp"-->
|
||||
<!-- android:clickable="true"-->
|
||||
<!-- android:focusable="true"-->
|
||||
<!-- android:onClick="@{click}">-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_alipay_binder"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="@dimen/dp_15"
|
||||
android:text="@string/text_setting_bind_alipay_account"
|
||||
android:textColor="@color/text_title_282828"
|
||||
android:textSize="14sp" />
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/label_alipay_binder"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_centerVertical="true"-->
|
||||
<!-- android:layout_marginStart="@dimen/dp_15"-->
|
||||
<!-- android:text="@string/text_setting_bind_alipay_account"-->
|
||||
<!-- android:textColor="@color/text_title_282828"-->
|
||||
<!-- android:textSize="14sp" />-->
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_alipay_right"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginEnd="@dimen/dp_15"
|
||||
android:src="@drawable/arrow_right" />
|
||||
<!-- <ImageView-->
|
||||
<!-- android:id="@+id/iv_alipay_right"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_alignParentEnd="true"-->
|
||||
<!-- android:layout_centerVertical="true"-->
|
||||
<!-- android:layout_marginEnd="@dimen/dp_15"-->
|
||||
<!-- android:src="@drawable/arrow_right" />-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_alipay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginEnd="@dimen/dp_14"
|
||||
android:layout_toStartOf="@id/iv_alipay_right"
|
||||
android:layout_toEndOf="@id/label_alipay_binder"
|
||||
android:gravity="end"
|
||||
android:textColor="@color/text_normal_282828"
|
||||
android:textSize="12sp"
|
||||
tools:text="未绑定" />
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/tv_alipay"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_centerVertical="true"-->
|
||||
<!-- android:layout_marginEnd="@dimen/dp_14"-->
|
||||
<!-- android:layout_toStartOf="@id/iv_alipay_right"-->
|
||||
<!-- android:layout_toEndOf="@id/label_alipay_binder"-->
|
||||
<!-- android:gravity="end"-->
|
||||
<!-- android:textColor="@color/text_normal_282828"-->
|
||||
<!-- android:textSize="12sp"-->
|
||||
<!-- tools:text="未绑定" />-->
|
||||
|
||||
</RelativeLayout>
|
||||
<!-- </RelativeLayout>-->
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
|
@@ -598,76 +598,76 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_me_more"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:background="@drawable/shape_white_8dp_round"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/ll_setting_entrance">
|
||||
<!-- <LinearLayout-->
|
||||
<!-- android:id="@+id/ll_me_more"-->
|
||||
<!-- android:layout_width="0dp"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginStart="15dp"-->
|
||||
<!-- android:layout_marginTop="12dp"-->
|
||||
<!-- android:layout_marginEnd="15dp"-->
|
||||
<!-- android:background="@drawable/shape_white_8dp_round"-->
|
||||
<!-- android:orientation="vertical"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toBottomOf="@id/ll_setting_entrance">-->
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:includeFontPadding="false"
|
||||
android:text="更多服务"
|
||||
android:textColor="@color/text_normal_282828"
|
||||
android:textSize="15sp" />
|
||||
<!-- <TextView-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginStart="12dp"-->
|
||||
<!-- android:layout_marginTop="12dp"-->
|
||||
<!-- android:includeFontPadding="false"-->
|
||||
<!-- android:text="更多服务"-->
|
||||
<!-- android:textColor="@color/text_normal_282828"-->
|
||||
<!-- android:textSize="15sp" />-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_me_real_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:drawableStart="@drawable/ic_me_real_name"
|
||||
android:drawableEnd="@drawable/ic_me_arrow_more"
|
||||
android:gravity="center_vertical"
|
||||
android:onClick="@{click}"
|
||||
android:text="实名认证"
|
||||
android:textColor="@color/text_normal_282828"
|
||||
android:textSize="14sp" />
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/tv_me_real_name"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginStart="7dp"-->
|
||||
<!-- android:layout_marginTop="15dp"-->
|
||||
<!-- android:layout_marginEnd="10dp"-->
|
||||
<!-- android:drawableStart="@drawable/ic_me_real_name"-->
|
||||
<!-- android:drawableEnd="@drawable/ic_me_arrow_more"-->
|
||||
<!-- android:gravity="center_vertical"-->
|
||||
<!-- android:onClick="@{click}"-->
|
||||
<!-- android:text="实名认证"-->
|
||||
<!-- android:textColor="@color/text_normal_282828"-->
|
||||
<!-- android:textSize="14sp" />-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_me_youth_mode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:drawableStart="@drawable/ic_me_youth_mode"
|
||||
android:drawableEnd="@drawable/ic_me_arrow_more"
|
||||
android:gravity="center_vertical"
|
||||
android:onClick="@{click}"
|
||||
android:text="青少年模式"
|
||||
android:textColor="@color/text_normal_282828"
|
||||
android:textSize="14sp" />
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/tv_me_youth_mode"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginStart="7dp"-->
|
||||
<!-- android:layout_marginTop="9dp"-->
|
||||
<!-- android:layout_marginEnd="10dp"-->
|
||||
<!-- android:drawableStart="@drawable/ic_me_youth_mode"-->
|
||||
<!-- android:drawableEnd="@drawable/ic_me_arrow_more"-->
|
||||
<!-- android:gravity="center_vertical"-->
|
||||
<!-- android:onClick="@{click}"-->
|
||||
<!-- android:text="青少年模式"-->
|
||||
<!-- android:textColor="@color/text_normal_282828"-->
|
||||
<!-- android:textSize="14sp" />-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_me_service"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="7dp"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:drawableStart="@drawable/ic_me_service"
|
||||
android:drawableEnd="@drawable/ic_me_arrow_more"
|
||||
android:gravity="center_vertical"
|
||||
android:onClick="@{click}"
|
||||
android:text="客服中心"
|
||||
android:textColor="@color/text_normal_282828"
|
||||
android:textSize="14sp" />
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/tv_me_service"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginStart="7dp"-->
|
||||
<!-- android:layout_marginTop="9dp"-->
|
||||
<!-- android:layout_marginEnd="10dp"-->
|
||||
<!-- android:layout_marginBottom="10dp"-->
|
||||
<!-- android:drawableStart="@drawable/ic_me_service"-->
|
||||
<!-- android:drawableEnd="@drawable/ic_me_arrow_more"-->
|
||||
<!-- android:gravity="center_vertical"-->
|
||||
<!-- android:onClick="@{click}"-->
|
||||
<!-- android:text="客服中心"-->
|
||||
<!-- android:textColor="@color/text_normal_282828"-->
|
||||
<!-- android:textSize="14sp" />-->
|
||||
|
||||
</LinearLayout>
|
||||
<!-- </LinearLayout>-->
|
||||
|
||||
<com.nnbc123.app.ui.widget.rollviewpager.RollPagerView
|
||||
android:id="@+id/roll_view"
|
||||
@@ -680,7 +680,7 @@
|
||||
app:layout_constraintDimensionRatio="345:80"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/ll_me_more"
|
||||
app:layout_constraintTop_toBottomOf="@id/ll_setting_entrance"
|
||||
app:rollviewpager_hint_gravity="left"
|
||||
app:rollviewpager_hint_paddingBottom="8dp" />
|
||||
|
||||
|
@@ -0,0 +1,314 @@
|
||||
package com.nnbc123.library.common.util
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Process
|
||||
import android.provider.Settings
|
||||
import android.telephony.TelephonyManager
|
||||
import android.text.TextUtils
|
||||
import com.nnbc123.library.common.application.BaseApp
|
||||
import com.ut.device.UTDevice
|
||||
import java.io.RandomAccessFile
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* create by wushaocheng 2023/2/15
|
||||
* 获取设备id
|
||||
*/
|
||||
object DeviceUtil {
|
||||
private const val TAG = "DeviceUtils"
|
||||
private const val ANDROID_ID_KEY = "android_id"
|
||||
private const val cache_device_id = "cache_device_id"
|
||||
private var deviceId = ""
|
||||
private var mcc_mnc = ""
|
||||
private var mcc = ""
|
||||
private var mnc = ""
|
||||
@Volatile
|
||||
private var ANDROID_ID = ""
|
||||
|
||||
/**
|
||||
* 获取设备信息
|
||||
*/
|
||||
var deviceDesc = ""
|
||||
get() {
|
||||
if (!TextUtils.isEmpty(field)) {
|
||||
return field
|
||||
}
|
||||
field =
|
||||
String.format("%s-%s-%s", Build.MANUFACTURER, Build.MODEL, Build.VERSION.RELEASE)
|
||||
return field
|
||||
}
|
||||
private set
|
||||
private const val MB = (1024 * 1024).toLong()
|
||||
private var sLevelCache: LEVEL? = null
|
||||
private var sTotalMemory: Long = 0
|
||||
|
||||
/**
|
||||
* 获取设备等级,考虑到机身真实内存大小与参数规格里面的不太一致,排除系统可能占用的内存情况后,以下面方式来衡量:
|
||||
* 1.内存小于等于4GB,定为中低端机
|
||||
* 2.内存大于4GB,定为高端机
|
||||
*/
|
||||
fun getLevel(context: Context): LEVEL? {
|
||||
if (null != sLevelCache) {
|
||||
return sLevelCache
|
||||
}
|
||||
val totalMemory = getTotalMemory(context)
|
||||
sLevelCache = if (totalMemory > 4 * 1024 * MB) {
|
||||
//内存大于4GB,定为高端机
|
||||
LEVEL.HIGH
|
||||
} else {
|
||||
//内存小于等于4GB,定为中低端机
|
||||
LEVEL.LOW
|
||||
}
|
||||
return sLevelCache
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 当前进程id
|
||||
*/
|
||||
private val appId: Int
|
||||
get() = Process.myPid()
|
||||
|
||||
/**
|
||||
* 获取设备内存总大小
|
||||
*/
|
||||
private fun getTotalMemory(context: Context): Long {
|
||||
if (0L != sTotalMemory) {
|
||||
return sTotalMemory
|
||||
}
|
||||
val memInfo = ActivityManager.MemoryInfo()
|
||||
val am = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
am.getMemoryInfo(memInfo)
|
||||
sTotalMemory = memInfo.totalMem
|
||||
return sTotalMemory
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前设备是否处于低内存状态
|
||||
*/
|
||||
fun isLowMemory(context: Context): Boolean {
|
||||
val memInfo = ActivityManager.MemoryInfo()
|
||||
val am = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
am.getMemoryInfo(memInfo)
|
||||
return memInfo.lowMemory
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前进程剩余内存大小
|
||||
*/
|
||||
val appAvailableMemory: Long
|
||||
get() {
|
||||
val runtime = Runtime.getRuntime()
|
||||
return runtime.totalMemory() - runtime.freeMemory()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前设备CPU使用率
|
||||
*/
|
||||
val appCpuRate: Double
|
||||
get() {
|
||||
var cpuTime = 0L
|
||||
var appTime = 0L
|
||||
var cpuRate = 0.0
|
||||
var procStatFile: RandomAccessFile? = null
|
||||
var appStatFile: RandomAccessFile? = null
|
||||
try {
|
||||
procStatFile = RandomAccessFile("/proc/stat", "r")
|
||||
val procStatString = procStatFile.readLine()
|
||||
val procStats = procStatString.split(" ".toRegex()).dropLastWhile { it.isEmpty() }
|
||||
.toTypedArray()
|
||||
cpuTime =
|
||||
procStats[2].toLong() + procStats[3].toLong() + procStats[4].toLong() + procStats[5].toLong() + procStats[6].toLong() + procStats[7].toLong() + procStats[8].toLong()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
try {
|
||||
procStatFile?.close()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
try {
|
||||
appStatFile = RandomAccessFile("/proc/$appId/stat", "r")
|
||||
val appStatString = appStatFile.readLine()
|
||||
val appStats =
|
||||
appStatString.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
appTime = appStats[13].toLong() + appStats[14].toLong()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
try {
|
||||
appStatFile?.close()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
if (0L != cpuTime) {
|
||||
cpuRate = appTime.toDouble() / cpuTime.toDouble() * 100.0
|
||||
}
|
||||
return cpuRate
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备id
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getDeviceId(context: Context?): String {
|
||||
if (!TextUtils.isEmpty(deviceId)) {
|
||||
return deviceId
|
||||
}
|
||||
deviceId = Config.getInstance(context).getString(cache_device_id, "")
|
||||
if (!TextUtils.isEmpty(deviceId)) {
|
||||
return deviceId
|
||||
}
|
||||
deviceId = UTDevice.getUtdid(context)
|
||||
if (TextUtils.isEmpty(deviceId)) {
|
||||
deviceId = handyDevicesId
|
||||
Logger.info(TAG, "use handy deviceId=$deviceId")
|
||||
} else {
|
||||
Logger.info(TAG, "use system deviceId=$deviceId")
|
||||
}
|
||||
//缓存上次取到的数据,避免有些机型每次打开APP都能拿到一个新的设备id
|
||||
Config.getInstance(context).putString(cache_device_id, deviceId)
|
||||
return deviceId
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 获取系统id
|
||||
*/
|
||||
@SuppressLint("HardwareIds")
|
||||
@JvmStatic
|
||||
fun getAndroidID(): String {
|
||||
if (!TextUtils.isEmpty(ANDROID_ID)) {
|
||||
Logger.info(TAG, "getAndroidID from cache, ANDROID_ID=$ANDROID_ID")
|
||||
return ANDROID_ID
|
||||
}
|
||||
ANDROID_ID = SPUtils.getString(ANDROID_ID_KEY, "")
|
||||
if (!TextUtils.isEmpty(ANDROID_ID)) {
|
||||
Logger.info(TAG, "getAndroidID from SP, ANDROID_ID=$ANDROID_ID")
|
||||
return ANDROID_ID
|
||||
}
|
||||
ANDROID_ID = Settings.Secure.getString(
|
||||
BaseApp.getContext().contentResolver,
|
||||
Settings.Secure.ANDROID_ID
|
||||
)
|
||||
Logger.info(TAG, "getAndroidID from system, ANDROID_ID=$ANDROID_ID")
|
||||
SPUtils.putString(ANDROID_ID_KEY, ANDROID_ID)
|
||||
return ANDROID_ID
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 手动组装设备id
|
||||
*/
|
||||
private val handyDevicesId: String
|
||||
get() {
|
||||
val devIDShort =
|
||||
"35" + Build.BOARD.length % 10 + Build.BRAND.length % 10 + Build.DEVICE.length % 10 + Build.MANUFACTURER.length % 10 + Build.MODEL.length % 10 + Build.PRODUCT.length % 10
|
||||
val serial = "serial"
|
||||
return UUID(devIDShort.hashCode().toLong(), serial.hashCode().toLong()).toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 移动设备国家代码(英语:Mobile Country Code,MCC)+移动设备网络代码(英语:Mobile Network Code,MNC)
|
||||
*/
|
||||
private fun getMCC_MNC(context: Context): String {
|
||||
if (!TextUtils.isEmpty(mcc_mnc)) {
|
||||
return mcc_mnc
|
||||
}
|
||||
try {
|
||||
val telManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||
mcc_mnc = telManager.simOperator
|
||||
if (!TextUtils.isEmpty(mcc_mnc)) {
|
||||
//双卡双待手机会返回[46001,46002] or [,46007] or [46007,]这种格式,
|
||||
//先取第一个,如果第一个为空且第二个不为空,则取第二个
|
||||
val s = mcc_mnc.split(",".toRegex()).dropLastWhile { it.isEmpty() }
|
||||
.toTypedArray()
|
||||
if (s.isNotEmpty() && !TextUtils.isEmpty(s[0])) {
|
||||
mcc_mnc = s[0]
|
||||
} else {
|
||||
if (s.size == 2 && !TextUtils.isEmpty(s[1])) {
|
||||
mcc_mnc = s[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
return mcc_mnc
|
||||
} catch (e: Exception) {
|
||||
Logger.error(TAG, e.message)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 移动设备国家代码(英语:Mobile Country Code,MCC),三位
|
||||
*/
|
||||
fun getMCC(context: Context): String {
|
||||
if (!TextUtils.isEmpty(mcc)) {
|
||||
return mcc
|
||||
}
|
||||
try {
|
||||
val mcc_mnc = getMCC_MNC(context)
|
||||
if (mcc_mnc.length > 2) {
|
||||
mcc = mcc_mnc.substring(0, 3)
|
||||
return mcc
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.error(TAG, e.message)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 移动设备网络代码(英语:Mobile Network Code,MNC),两位或三位
|
||||
*/
|
||||
fun getMNC(context: Context): String {
|
||||
if (!TextUtils.isEmpty(mnc)) {
|
||||
return mnc
|
||||
}
|
||||
try {
|
||||
val mcc_mnc = getMCC_MNC(context)
|
||||
if (mcc_mnc.length > 3) {
|
||||
mnc = mcc_mnc.substring(3)
|
||||
return mnc
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.error(TAG, e.message)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查指定包名的APP是否已安装了
|
||||
*
|
||||
* @param context 上下文对象
|
||||
* @param packageName 包名
|
||||
* @return 是否有安装指定包名的APP,true代表已安装,false代表未安装
|
||||
*/
|
||||
fun isAppInstalled(context: Context?, packageName: String): Boolean {
|
||||
return if (context == null) {
|
||||
false
|
||||
} else {
|
||||
var installed = false
|
||||
try {
|
||||
val pm = context.packageManager
|
||||
val info = pm.getApplicationInfo(packageName, 0)
|
||||
if (info != null) {
|
||||
installed = true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.error(TAG, "isAppInstalled packageName=$packageName", e)
|
||||
}
|
||||
installed
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备等级划分方案参考Matrix框架,
|
||||
* 参考:[...](https://github.com/Tencent/matrix/blob/master/matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/util/DeviceUtil.java)
|
||||
*/
|
||||
enum class LEVEL(var value: Int) {
|
||||
HIGH(2), LOW(1);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user