| | |
| | | package com.weikou.beibeivideo.ui.login; |
| | | |
| | | import android.Manifest; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.SharedPreferences; |
| | | import android.content.SharedPreferences.Editor; |
| | | import android.content.pm.PackageInfo; |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | |
| | | import android.widget.Toast; |
| | | |
| | | import com.lcjian.library.dialog.DialogUtil; |
| | | import com.lcjian.library.permission.PermissionHelper; |
| | | import com.lcjian.library.permission.PermissionInterface; |
| | | import com.lcjian.library.util.SingleToast; |
| | | import com.lcjian.library.util.common.DeviceUtil; |
| | | import com.lcjian.library.util.common.StringUtils; |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public class LoginActivity extends BaseActivity implements OnClickListener { |
| | | import androidx.annotation.NonNull; |
| | | |
| | | public class LoginActivity extends BaseActivity implements OnClickListener, PermissionInterface { |
| | | public static final int RESULT_LOGIN = 10; |
| | | private LinearLayout ll_login_qq, ll_login_wx; |
| | | private boolean isTouchLogin;// 用户是否点击登录 |
| | |
| | | private TextView tv_forget_pwd; |
| | | private TextView tv_register; |
| | | private TextView tv_login, tv_other_login, tv_title; |
| | | private PermissionHelper mPermissionsChecker; // 权限检测器 检测是否有储存卡写入读取权限 |
| | | |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | //防止截屏攻击风险 |
| | | if(!BeibeiConstant.IS_TEST) { |
| | | if (!BeibeiConstant.IS_TEST) { |
| | | getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); |
| | | } |
| | | setContentView(R.layout.act_login); |
| | |
| | | findViewById(R.id.tv_privacy_policy).setOnClickListener(this); |
| | | |
| | | setLoginType(false); |
| | | |
| | | mPermissionsChecker = new PermissionHelper(this, this);//权限 |
| | | } |
| | | |
| | | private void setLoginType(boolean email) { |
| | |
| | | SingleToast.showToast(LoginActivity.this, "选择同意用户协议后方可登录"); |
| | | break; |
| | | } |
| | | if (Build.VERSION.SDK_INT < 30) { |
| | | //Android 11以下的要请求安装应用列表 |
| | | if (mPermissionsChecker.lacksPermissions(getPermissions())) {//检测是否有写入的权限 |
| | | mPermissionsChecker.showNormalDialog("设备应用列表权限说明", "判断设备是否安装QQ/微信,用于三方登录"); |
| | | return; |
| | | } |
| | | } |
| | | if (isQQClientAvailable(getApplicationContext())) { |
| | | loginType = "1"; |
| | | // qq登录逻辑处理 点击登录后需要暂时锁定返回键和返回功能 不然会报错 |
| | |
| | | if (!cb_user_agreement.isChecked()) { |
| | | SingleToast.showToast(LoginActivity.this, "选择同意用户协议后方可登录"); |
| | | break; |
| | | } |
| | | |
| | | if (Build.VERSION.SDK_INT < 30) { |
| | | //Android 11以下的要请求安装应用列表 |
| | | if (mPermissionsChecker.lacksPermissions(getPermissions())) {//检测是否有写入的权限 |
| | | mPermissionsChecker.showNormalDialog("设备应用列表权限说明", "判断设备是否安装QQ/微信,用于三方登录"); |
| | | return; |
| | | } |
| | | } |
| | | if (isWXClientAvailable(getApplicationContext())) { |
| | | loginType = "2"; |
| | |
| | | * 判断qq是否可用 |
| | | */ |
| | | public static boolean isQQClientAvailable(Context context) { |
| | | List<PackageInfo> pinfo = DeviceUtil.getInstalledPackagesCache(context); |
| | | if (pinfo != null) { |
| | | for (int i = 0; i < pinfo.size(); i++) { |
| | | String pn = pinfo.get(i).packageName; |
| | | if (pn.equals("com.tencent.mobileqq")) { |
| | | return true; |
| | | } |
| | | } |
| | | PackageManager packageManager = context.getPackageManager(); |
| | | try { |
| | | // 尝试获取应用信息 |
| | | packageManager.getPackageInfo("com.tencent.mobileqq", PackageManager.GET_ACTIVITIES); |
| | | return true; |
| | | } catch (PackageManager.NameNotFoundException e) { |
| | | // 应用未找到,返回 false |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public static boolean isWXClientAvailable(Context context) { |
| | | List<PackageInfo> pinfo = DeviceUtil.getInstalledPackagesCache(context); |
| | | if (pinfo != null) { |
| | | for (int i = 0; i < pinfo.size(); i++) { |
| | | String pn = pinfo.get(i).packageName; |
| | | if (pn.equals("com.tencent.mm")) { |
| | | return true; |
| | | } |
| | | } |
| | | PackageManager packageManager = context.getPackageManager(); |
| | | try { |
| | | // 尝试获取应用信息 |
| | | packageManager.getPackageInfo("com.tencent.mm", PackageManager.GET_ACTIVITIES); |
| | | return true; |
| | | } catch (PackageManager.NameNotFoundException e) { |
| | | // 应用未找到,返回 false |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | UMAuthListener authListener = new UMAuthListener() { |
| | |
| | | finish(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int getPermissionsRequestCode() { |
| | | return 20001; |
| | | } |
| | | |
| | | @Override |
| | | public String[] getPermissions() { |
| | | return new String[]{Manifest.permission.INSTALL_PACKAGES}; |
| | | } |
| | | |
| | | @Override |
| | | public void requestPermissionsSuccess() { |
| | | DeviceUtil.getInstalledPackages(this); |
| | | } |
| | | |
| | | @Override |
| | | public void requestPermissionsFail() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| | | if (mPermissionsChecker.requestPermissionsResult(requestCode, permissions, grantResults)) { |
| | | //权限请求结果,并已经处理了该回调 |
| | | return; |
| | | } |
| | | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| | | } |
| | | |
| | | } |