diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 0384b90..ce320ed 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/build.gradle b/app/build.gradle index 2618f2a..ec402d1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -122,16 +122,6 @@ dependencies { implementation librarys.cardview implementation librarys.multidex - /*-----------------------------------------*/ - - /*Umeng统计*/ - implementation 'com.umeng.sdk:common:1.5.3' - implementation 'com.umeng.sdk:analytics:7.5.3' - /*极光推送*/ - implementation files('libs/jcore-android_v1.1.2.jar') - implementation files('libs/jpush-android_v3.0.5.jar') - - /*-----------------------------------------*/ /*注解*/ implementation 'com.jakewharton:butterknife:10.2.3' @@ -142,14 +132,15 @@ dependencies { /*解析Json*/ implementation 'com.google.code.gson:gson:2.8.5' /*网络相关*/ - implementation 'com.squareup.okhttp3:okhttp:3.11.0' - implementation 'com.squareup.retrofit2:retrofit:2.1.0' - implementation 'com.squareup.retrofit2:converter-gson:2.1.0' + implementation 'com.squareup.okhttp3:okhttp:3.12.13' + implementation 'com.squareup.retrofit2:retrofit:2.6.0' + implementation 'com.squareup.retrofit2:converter-gson:2.6.0' /*图片加载Glide*/ - implementation 'com.github.bumptech.glide:glide:4.8.0' - implementation 'jp.wasabeef:glide-transformations:2.0.2' + implementation 'com.github.bumptech.glide:glide:4.12.0' + annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' + implementation 'jp.wasabeef:glide-transformations:4.3.0' /*数据存储*/ - implementation 'com.tencent:mmkv-static:1.2.2' + implementation 'com.tencent:mmkv-static:1.2.6' /*日志*/ implementation 'com.github.zhaokaiqiang.klog:library:1.6.0' /*下拉刷新框架*/ @@ -161,7 +152,7 @@ dependencies { /*解析HTML页面*/ implementation 'org.jsoup:jsoup:1.9.2' /*权限库*/ - implementation 'com.yanzhenjie:permission:2.0.0-rc4' + implementation 'com.github.getActivity:XXPermissions:10.8' /*ViewPager指示器*/ implementation 'com.ogaclejapan.smarttablayout:library:1.6.1@aar' /*菜单*/ @@ -182,7 +173,7 @@ dependencies { /* 背景可以移动的View */ implementation 'com.flaviofaria:kenburnsview:1.0.7' /* 圆形图片 */ - implementation 'de.hdodenhof:circleimageview:2.1.0' + implementation 'de.hdodenhof:circleimageview:3.1.0' /* 滚轮选择器 */ implementation 'com.contrarywind:Android-PickerView:3.2.5' /* 图片选择 */ @@ -195,9 +186,10 @@ dependencies { /*-----------------------------------------*/ /*图片浏览*/ - implementation 'com.github.maning0303:MNImageBrowser:V1.3.5' + implementation 'com.github.maning0303:MNImageBrowser:V1.3.7' /*二维码扫描*/ - implementation 'com.github.maning0303:MNZXingCode:V2.1.4' + implementation 'com.google.zxing:core:3.3.3' + implementation 'com.github.maning0303:MNZXingCode:V2.1.8' /*翻滚广告条TextView*/ implementation 'com.github.maning0303:SwitcherView:v1.0.4' /* 提示框 */ diff --git a/app/libs/jcore-android_v1.1.2.jar b/app/libs/jcore-android_v1.1.2.jar deleted file mode 100644 index 605d647..0000000 Binary files a/app/libs/jcore-android_v1.1.2.jar and /dev/null differ diff --git a/app/libs/jpush-android_v3.0.5.jar b/app/libs/jpush-android_v3.0.5.jar deleted file mode 100644 index fa11c4e..0000000 Binary files a/app/libs/jpush-android_v3.0.5.jar and /dev/null differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d25ae7f..6aeafa1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,9 +7,6 @@ - @@ -45,7 +42,8 @@ android:theme="@style/DayTheme" android:usesCleartextTraffic="true" tools:replace="icon,label,theme,allowBackup"> - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - @@ -208,11 +103,7 @@ android:screenOrientation="portrait" /> - - - - @@ -223,13 +114,6 @@ - - - - @@ -241,7 +125,6 @@ - diff --git a/app/src/main/java/com/maning/gankmm/app/MyApplication.java b/app/src/main/java/com/maning/gankmm/app/MyApplication.java index b2849fe..45e9d09 100644 --- a/app/src/main/java/com/maning/gankmm/app/MyApplication.java +++ b/app/src/main/java/com/maning/gankmm/app/MyApplication.java @@ -18,14 +18,11 @@ import com.readystatesoftware.chuck.ChuckInterceptor; import com.socks.library.KLog; import com.tencent.mmkv.MMKV; -import com.umeng.analytics.MobclickAgent; -import com.umeng.commonsdk.UMConfigure; import java.io.File; import java.io.IOException; import java.util.concurrent.TimeUnit; -import cn.jpush.android.api.JPushInterface; import okhttp3.Cache; import okhttp3.CacheControl; import okhttp3.Interceptor; @@ -58,45 +55,9 @@ public void onCreate() { //初始化Log initLog(); - //Jpush - initJpush(); - //初始化异常捕获 initCrash(); - //Umeng统计相关 - initUmeng(); - - //开启违例检测:StrictMode - if (BuildConfig.LOG_DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { - StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); - StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build()); - } - - } - - private void initUmeng() { - //禁止默认的页面统计方式 - MobclickAgent.openActivityDurationTrack(false); - //获取渠道 - String channel = ChannelReaderUtil.getChannel(getApplicationContext()); - if(TextUtils.isEmpty(channel)){ - channel = "gankmm_bd"; - } - /** - * 初始化common库 - * 参数1:上下文,不能为空 - * 参数2:友盟 app key - * 参数3:友盟 channel - * 参数4:设备类型,UMConfigure.DEVICE_TYPE_PHONE为手机、UMConfigure.DEVICE_TYPE_BOX为盒子,默认为手机 - * 参数5:Push推送业务的secret - */ - UMConfigure.init(this, "56dce179e0f55ac5d700046c", channel, UMConfigure.DEVICE_TYPE_PHONE, ""); - /** - * 设置组件化的Log开关 - * 参数: boolean 默认为false,如需查看LOG设置为true - */ - UMConfigure.setLogEnabled(BuildConfig.LOG_DEBUG); } private void initLog() { @@ -104,16 +65,6 @@ private void initLog() { } - private void initJpush() { - try { - JPushInterface.setDebugMode(BuildConfig.LOG_DEBUG); - JPushInterface.init(this); - } catch (Exception e) { - KLog.e(); - } - - } - private void initBase() { application = this; mHandler = new Handler(); diff --git a/app/src/main/java/com/maning/gankmm/ui/activity/SettingActivity.java b/app/src/main/java/com/maning/gankmm/ui/activity/SettingActivity.java index 531a2e9..4c6e150 100644 --- a/app/src/main/java/com/maning/gankmm/ui/activity/SettingActivity.java +++ b/app/src/main/java/com/maning/gankmm/ui/activity/SettingActivity.java @@ -1,11 +1,14 @@ package com.maning.gankmm.ui.activity; +import android.Manifest; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; + import android.view.MenuItem; import android.widget.ImageView; import android.widget.Toast; @@ -24,7 +27,7 @@ import com.maning.gankmm.utils.MySnackbar; import com.maning.gankmm.utils.NetUtils; import com.maning.gankmm.utils.NotifyUtil; -import com.maning.gankmm.utils.PermissionUtils; +import com.maning.gankmm.utils.PermissionManager; import com.maning.gankmm.utils.SharePreUtil; import com.maning.updatelibrary.InstallUtils; import com.socks.library.KLog; @@ -161,18 +164,18 @@ private void showCacheDialog() { @Override public void onConfirm() { - PermissionUtils.checkWritePermission(mContext, new PermissionUtils.PermissionCallBack() { - @Override - public void onGranted() { - settingPresenter.cleanCache(); - } - - @Override - public void onDenied() { - showProgressError("获取存储权限失败,请前往设置页面打开存储权限"); - } - }); + PermissionManager.with(mActivity) + .callback(new PermissionManager.OnPermissionCallback() { + @Override + public void onGranted() { + settingPresenter.cleanCache(); + } + @Override + public void onDenied(boolean never) { + showProgressError("获取存储权限失败,请前往设置页面打开存储权限"); + } + }).request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE); } @Override @@ -275,30 +278,19 @@ public void showAppUpdateDialog(AppUpdateInfo appUpdateInfo) { new DialogUtils.OnDialogClickListener() { @Override public void onConfirm() { - PermissionUtils.checkWritePermission(mContext, new PermissionUtils.PermissionCallBack() { - @Override - public void onGranted() { - //更新版本 - showDownloadDialog(SettingActivity.this.appUpdateInfo); - } - - @Override - public void onDenied() { - showProgressError("获取存储权限失败,请前往设置页面打开存储权限"); - } - }); -// // 先判断是否有权限。 -// if (AndPermission.hasPermission(SettingActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { -// // 有权限,直接do anything. -// //更新版本 -// showDownloadDialog(SettingActivity.this.appUpdateInfo); -// } else { -// // 申请权限。 -// AndPermission.with(SettingActivity.this) -// .requestCode(100) -// .permission(Manifest.permission.WRITE_EXTERNAL_STORAGE) -// .send(); -// } + PermissionManager.with(mActivity) + .callback(new PermissionManager.OnPermissionCallback() { + @Override + public void onGranted() { + //更新版本 + showDownloadDialog(SettingActivity.this.appUpdateInfo); + } + + @Override + public void onDenied(boolean never) { + showProgressError("获取存储权限失败,请前往设置页面打开存储权限"); + } + }).request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE); } @Override diff --git a/app/src/main/java/com/maning/gankmm/ui/activity/SupportPayActivity.java b/app/src/main/java/com/maning/gankmm/ui/activity/SupportPayActivity.java index 9f72bbb..6a15c75 100644 --- a/app/src/main/java/com/maning/gankmm/ui/activity/SupportPayActivity.java +++ b/app/src/main/java/com/maning/gankmm/ui/activity/SupportPayActivity.java @@ -1,14 +1,16 @@ package com.maning.gankmm.ui.activity; +import android.Manifest; import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; -import androidx.appcompat.widget.Toolbar; import android.view.MenuItem; import android.widget.ImageView; import android.widget.TextView; +import androidx.appcompat.widget.Toolbar; + import com.maning.gankmm.R; import com.maning.gankmm.app.MyApplication; import com.maning.gankmm.constant.Constants; @@ -16,7 +18,7 @@ import com.maning.gankmm.ui.base.BaseActivity; import com.maning.gankmm.utils.BitmapUtils; import com.maning.gankmm.utils.MySnackbar; -import com.maning.gankmm.utils.PermissionUtils; +import com.maning.gankmm.utils.PermissionManager; import java.io.File; @@ -86,31 +88,19 @@ public void btn_changge_type() { @OnClick(R.id.btn_save) public void btn_save() { + PermissionManager.with(mActivity) + .callback(new PermissionManager.OnPermissionCallback() { + @Override + public void onGranted() { + //保存图片 + savePayImage(); + } - PermissionUtils.checkWritePermission(mContext, new PermissionUtils.PermissionCallBack() { - @Override - public void onGranted() { - //保存图片 - savePayImage(); - } - - @Override - public void onDenied() { - showProgressError("获取存储权限失败,请前往设置页面打开存储权限"); - } - }); -// //先判断是否有权限。 -// if (AndPermission.hasPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { -// // 有权限,直接do anything. -// savePayImage(); -// } else { -// // 申请权限。 -// AndPermission.with(this) -// .requestCode(101) -// .permission(Manifest.permission.WRITE_EXTERNAL_STORAGE) -// .send(); -// } - + @Override + public void onDenied(boolean never) { + showProgressError("获取存储权限失败,请前往设置页面打开存储权限"); + } + }).request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE); } private void savePayImage() { @@ -160,33 +150,4 @@ private Bitmap getBitmapFromImageView(ImageView imageView) { return bitmap; } -// @Override -// public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { -// // 只需要调用这一句,其它的交给AndPermission吧,最后一个参数是PermissionListener。 -// AndPermission.onRequestPermissionsResult(requestCode, permissions, grantResults, listener); -// } -// -// private PermissionListener listener = new PermissionListener() { -// @Override -// public void onSucceed(int requestCode, List grantedPermissions) { -// MySnackbar.makeSnackBarBlack(toolbar, "权限申请成功"); -// // 权限申请成功回调。 -// savePayImage(); -// } -// -// @Override -// public void onFailed(int requestCode, List deniedPermissions) { -// // 权限申请失败回调。 -// // 用户否勾选了不再提示并且拒绝了权限,那么提示用户到设置中授权。 -// if (AndPermission.hasAlwaysDeniedPermission(SupportPayActivity.this, deniedPermissions)) { -// // 第二种:用自定义的提示语。 -// AndPermission.defaultSettingDialog(SupportPayActivity.this, 300) -// .setTitle("权限申请失败") -// .setMessage("我们需要的一些权限被您拒绝或者系统发生错误申请失败,请您到设置页面手动授权,否则功能无法正常使用!") -// .setPositiveButton("好,去设置") -// .show(); -// } -// } -// }; - } diff --git a/app/src/main/java/com/maning/gankmm/ui/adapter/RecycleMoreAdapter.java b/app/src/main/java/com/maning/gankmm/ui/adapter/RecycleMoreAdapter.java index c251c87..ea3524d 100644 --- a/app/src/main/java/com/maning/gankmm/ui/adapter/RecycleMoreAdapter.java +++ b/app/src/main/java/com/maning/gankmm/ui/adapter/RecycleMoreAdapter.java @@ -1,16 +1,17 @@ package com.maning.gankmm.ui.adapter; -import android.app.Activity; import android.content.Context; import android.content.Intent; -import androidx.recyclerview.widget.DefaultItemAnimator; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import androidx.fragment.app.FragmentActivity; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import com.maning.gankmm.R; import com.maning.gankmm.listeners.OnItemClickListener; import com.maning.gankmm.ui.activity.tools.ChineseCalendarActivity; @@ -98,7 +99,7 @@ public void onItemClick(View view, int position) { if (title.equals("手机号码归属地")) { context.startActivity(new Intent(context, PhoneAddressActivity.class)); } else if (title.equals("扫一扫")) { - ZxingScanUtils.open((Activity) context); + ZxingScanUtils.open((FragmentActivity) context); } else if (title.equals("扫码记录")) { context.startActivity(new Intent(context, ScanResultActivity.class)); } else if (title.equals("IP地址")) { diff --git a/app/src/main/java/com/maning/gankmm/ui/base/BaseActivity.java b/app/src/main/java/com/maning/gankmm/ui/base/BaseActivity.java index 12c4dc7..8f41cb4 100644 --- a/app/src/main/java/com/maning/gankmm/ui/base/BaseActivity.java +++ b/app/src/main/java/com/maning/gankmm/ui/base/BaseActivity.java @@ -13,7 +13,6 @@ import com.maning.gankmm.skin.SkinManager; import com.maning.mndialoglibrary.MProgressDialog; import com.maning.mndialoglibrary.MStatusDialog; -import com.umeng.analytics.MobclickAgent; /** * Created by maning on 16/3/2. @@ -116,23 +115,11 @@ protected void onDestroy() { @Override protected void onResume() { super.onResume(); - // MainActivity 内嵌套Fragment,应在Fragment中统计页面 - String className = this.getClass().getSimpleName(); - if (!"MainActivity".equals(className)) { - MobclickAgent.onPageStart(className); // 统计页面 - } - MobclickAgent.onResume(this); //统计时长 } @Override protected void onPause() { super.onPause(); - // MainActivity 内嵌套Fragment,应在Fragment中统计页面 - String className = this.getClass().getSimpleName(); - if (!"MainActivity".equals(className)) { - MobclickAgent.onPageEnd(className); // 统计页面 - } - MobclickAgent.onPause(this); } diff --git a/app/src/main/java/com/maning/gankmm/ui/base/BaseFragment.java b/app/src/main/java/com/maning/gankmm/ui/base/BaseFragment.java index 76b6470..1f86fec 100644 --- a/app/src/main/java/com/maning/gankmm/ui/base/BaseFragment.java +++ b/app/src/main/java/com/maning/gankmm/ui/base/BaseFragment.java @@ -2,12 +2,12 @@ import android.content.Context; import android.os.Bundle; + import androidx.fragment.app.Fragment; import com.maning.gankmm.R; import com.maning.mndialoglibrary.MProgressDialog; import com.maning.mndialoglibrary.MStatusDialog; -import com.umeng.analytics.MobclickAgent; public class BaseFragment extends Fragment { @@ -50,20 +50,11 @@ public void dissmissProgressDialog() { @Override public void onResume() { super.onResume(); - //CategoryFragment 内嵌套Fragment,统计子页面 - if (!"CategoryFragment".equals(className)) { - MobclickAgent.onPageStart(className); - } } @Override public void onPause() { super.onPause(); - //CategoryFragment 内嵌套Fragment,统计子页面 - if (!"CategoryFragment".equals(className)) { - MobclickAgent.onPageEnd(className); - } - } } diff --git a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/ImageBrowserUtils.java b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/ImageBrowserUtils.java index b56b5c9..e6944d2 100644 --- a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/ImageBrowserUtils.java +++ b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/ImageBrowserUtils.java @@ -1,5 +1,6 @@ package com.maning.gankmm.ui.imagebrowser; +import android.Manifest; import android.app.WallpaperManager; import android.content.Context; import android.graphics.Bitmap; @@ -16,7 +17,7 @@ import com.maning.gankmm.ui.dialog.ListFragmentDialog; import com.maning.gankmm.utils.BitmapUtils; import com.maning.gankmm.utils.IntentUtils; -import com.maning.gankmm.utils.PermissionUtils; +import com.maning.gankmm.utils.PermissionManager; import com.maning.gankmm.utils.ThreadPoolUtils; import com.maning.imagebrowserlibrary.listeners.OnLongClickListener; import com.maning.imagebrowserlibrary.model.ImageBrowserConfig; @@ -87,17 +88,18 @@ public static void showBottomSheet(final FragmentActivity context, final ImageVi public void onItemClick(View view, int position) { if (position == 0) { //保存图片 - PermissionUtils.checkWritePermission(context, new PermissionUtils.PermissionCallBack() { - @Override - public void onGranted() { - saveImage(context, imageView, url); - } - - @Override - public void onDenied() { - showProgressError(context, "获取存储权限失败,请前往设置页面打开存储权限"); - } - }); + PermissionManager.with(context) + .callback(new PermissionManager.OnPermissionCallback() { + @Override + public void onGranted() { + saveImage(context, imageView, url); + } + + @Override + public void onDenied(boolean never) { + showProgressError(context, "获取存储权限失败,请前往设置页面打开存储权限"); + } + }).request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE); } else if (position == 1) { IntentUtils.startAppShareText(context, "GankMM图片分享", "分享图片:" + url); } else if (position == 2) { diff --git a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java index bbf8328..e0455ca 100644 --- a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java +++ b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/MainPresenterImpl.java @@ -1,21 +1,24 @@ package com.maning.gankmm.ui.presenter.impl; +import android.Manifest; import android.content.Context; +import androidx.fragment.app.FragmentActivity; + import com.amap.api.location.AMapLocation; import com.maning.gankmm.R; import com.maning.gankmm.app.MyApplication; import com.maning.gankmm.bean.fir.AppUpdateInfo; import com.maning.gankmm.bean.weather.WeatherInfoBean; import com.maning.gankmm.constant.Constants; -import com.maning.gankmm.http.update.UpdateApi; import com.maning.gankmm.http.callback.CommonHttpCallback; +import com.maning.gankmm.http.update.UpdateApi; import com.maning.gankmm.http.weather.WeatherApi; import com.maning.gankmm.ui.iView.IMainView; import com.maning.gankmm.ui.presenter.IMainPresenter; import com.maning.gankmm.utils.LocationUtils; import com.maning.gankmm.utils.NetUtils; -import com.maning.gankmm.utils.PermissionUtils; +import com.maning.gankmm.utils.PermissionManager; import com.maning.gankmm.utils.SharePreUtil; import com.maning.gankmm.utils.ThreadPoolUtils; @@ -74,19 +77,19 @@ public void onFail(int code, String message) { @Override public void getLocationInfo() { - PermissionUtils.checkLocationPermission(context, new PermissionUtils.PermissionCallBack() { - @Override - public void onGranted() { - //高德获取位置信息 - requestLocationInfo(); - } - - @Override - public void onDenied() { - mView.showToast("获取定位权限失败,请前往设置页面打开定位权限"); - } - }); + PermissionManager.with((FragmentActivity) context) + .callback(new PermissionManager.OnPermissionCallback() { + @Override + public void onGranted() { + //高德获取位置信息 + requestLocationInfo(); + } + @Override + public void onDenied(boolean never) { + mView.showToast("获取定位权限失败,请前往设置页面打开定位权限"); + } + }).request(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION); } @Override diff --git a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/SettingPresenterImpl.java b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/SettingPresenterImpl.java index 2df5928..0c8eca8 100644 --- a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/SettingPresenterImpl.java +++ b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/SettingPresenterImpl.java @@ -28,7 +28,6 @@ import java.io.File; import java.util.Arrays; -import cn.jpush.android.api.JPushInterface; /** * Created by maning on 16/6/21. @@ -45,20 +44,7 @@ public SettingPresenterImpl(Context context, ISettingView iSettingView) { @Override public void initPushState() { - boolean jpush = SharePreUtil.getBooleanData(context, Constants.SPJpush, true); - if (jpush) { - JPushInterface.resumePush(context.getApplicationContext()); - if (mView == null) { - return; - } - mView.openPush(); - } else { - JPushInterface.stopPush(context.getApplicationContext()); - if (mView == null) { - return; - } - mView.closePush(); - } + } @Override @@ -122,23 +108,6 @@ public void initHeadLine() { @Override public void changePushState() { - if (mView == null) { - return; - } - try { - boolean jpush = SharePreUtil.getBooleanData(context, Constants.SPJpush, true); - if (!jpush) { - SharePreUtil.saveBooleanData(context, Constants.SPJpush, true); - JPushInterface.resumePush(context.getApplicationContext()); - mView.openPush(); - } else { - SharePreUtil.saveBooleanData(context, Constants.SPJpush, false); - mView.closePush(); - JPushInterface.stopPush(context.getApplicationContext()); - } - } catch (Exception e) { - KLog.e("changePushState Exception:" + e.toString()); - } } diff --git a/app/src/main/java/com/maning/gankmm/ui/receiver/MyReceiver.java b/app/src/main/java/com/maning/gankmm/ui/receiver/MyReceiver.java deleted file mode 100644 index c841863..0000000 --- a/app/src/main/java/com/maning/gankmm/ui/receiver/MyReceiver.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.maning.gankmm.ui.receiver; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.text.TextUtils; -import android.util.Log; - -import com.maning.gankmm.ui.activity.GankActivity; -import com.maning.gankmm.ui.activity.MainActivity; -import com.maning.gankmm.ui.activity.WebActivity; -import com.maning.gankmm.utils.IntentUtils; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.Iterator; - -import cn.jpush.android.api.JPushInterface; - -/** - * 自定义接收器 - *

- * 如果不定义这个 Receiver,则: - * 1) 默认用户会打开主界面 - * 2) 接收不到自定义消息 - */ -public class MyReceiver extends BroadcastReceiver { - private static final String TAG = "JPush"; - - //推送的字段 - public static final String PUSH_KEY_TYPE = "type"; //类型 - //三种类型 - public static final String PUSH_KEY_URL = "url"; //地址 - public static final String PUSH_KEY_TITLE = "title"; //地址 + title - public static final String PUSH_KEY_DATE = "date"; //时间 - public static final String PUSH_KEY_TEXT = "text"; //文字展示 - - private Context context; - - @Override - public void onReceive(Context context, Intent intent) { - this.context = context; - Bundle bundle = intent.getExtras(); - Log.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle)); - - if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { - Log.d(TAG, "[MyReceiver] 用户点击打开了通知"); - - if (bundle != null) { - //取消通知 - int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID); - JPushInterface.clearNotificationById(this.context, notifactionId); - //其他 - String result = bundle.getString(JPushInterface.EXTRA_EXTRA); - if (!TextUtils.isEmpty(result)) { - //解析Json串,获取动作 - openNotification(result); - } else { - startMainActivity(); - } - } else { - startMainActivity(); - } - - } - } - - private void openNotification(String result) { - try { - //解析推送 - JSONObject extrasJson = new JSONObject(result); - String url = extrasJson.optString(PUSH_KEY_URL); - String type = extrasJson.optString(PUSH_KEY_TYPE); - String text = extrasJson.optString(PUSH_KEY_TEXT); - String date = extrasJson.optString(PUSH_KEY_DATE); - String title = extrasJson.optString(PUSH_KEY_TITLE); - Log.d(TAG, "推动字段-----url:" + url + "---title:" + title + "---type:" + type + "---text:" + text + "---date:" + date); - //判断具体的打开什么页面 - openPage(type, url, title, text, date); - } catch (Exception e) { - Log.d(TAG, "推送解析出错"); - } - } - - private void openPage(String type, String url, String title, String text, String date) { - if (!TextUtils.isEmpty(url)) { - startWebActivity(url, title); - return; - } - if (!TextUtils.isEmpty(date)) { - startDayShowActivity(date); - return; - } - if (!TextUtils.isEmpty(text)) { - startMainActivity(text); - } - } - - private void startMainActivity() { - //打开自定义的Activity - Intent i = new Intent(context, MainActivity.class); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - context.startActivity(i); - } - - private void startMainActivity(String message) { - //打开自定义的Activity - Intent i = new Intent(context, MainActivity.class); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - i.putExtra(IntentUtils.PushMessage, message); - context.startActivity(i); - } - - private void startWebActivity(String url, String title) { - //打开自定义的Activity - Intent webIntent = new Intent(context, WebActivity.class); - webIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - webIntent.putExtra(IntentUtils.WebUrl, url); - webIntent.putExtra(IntentUtils.WebTitleFlag, "推送"); - webIntent.putExtra(IntentUtils.WebTitle, title); - context.startActivity(webIntent); - } - - private void startDayShowActivity(String date) { - Intent intent = new Intent(context.getApplicationContext(), GankActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(IntentUtils.DayDate, date); - context.startActivity(intent); - } - - - //--------------------------------华丽分割线-------------------------------------------- - - // 打印所有的 intent extra 数据 - private static String printBundle(Bundle bundle) { - StringBuilder sb = new StringBuilder(); - for (String key : bundle.keySet()) { - if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) { - sb.append("\nkey:" + key + ", value:" + bundle.getInt(key)); - } else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) { - sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key)); - } else if (key.equals(JPushInterface.EXTRA_EXTRA)) { - if (bundle.getString(JPushInterface.EXTRA_EXTRA).isEmpty()) { - Log.i(TAG, "This message has no Extra data"); - continue; - } - - try { - JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA)); - Iterator it = json.keys(); - - while (it.hasNext()) { - String myKey = it.next().toString(); - sb.append("\nkey:" + key + ", value: [" + - myKey + " - " + json.optString(myKey) + "]"); - } - } catch (JSONException e) { - Log.e(TAG, "Get message extra JSON error!"); - } - - } else { - sb.append("\nkey:" + key + ", value:" + bundle.getString(key)); - } - } - return sb.toString(); - } - -} - diff --git a/app/src/main/java/com/maning/gankmm/utils/Permission5Utils.java b/app/src/main/java/com/maning/gankmm/utils/Permission5Utils.java new file mode 100644 index 0000000..1ed6feb --- /dev/null +++ b/app/src/main/java/com/maning/gankmm/utils/Permission5Utils.java @@ -0,0 +1,170 @@ +package com.maning.gankmm.utils; + +import android.content.Context; +import android.database.Cursor; +import android.hardware.Camera; +import android.media.AudioFormat; +import android.media.AudioRecord; +import android.media.MediaRecorder; +import android.net.Uri; +import android.os.Environment; +import android.provider.ContactsContract; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + + +@Deprecated +public class Permission5Utils { + + //--------------------6.0以下权限处理------------------------- + + /** + * 相机是否可用 + * 返回true 表示可以使用 返回false表示不可以使用 + */ + public static boolean isCameraPermission() { + boolean isCanUse = true; + Camera mCamera = null; + try { + mCamera = Camera.open(); + Camera.Parameters mParameters = mCamera.getParameters(); //针对魅族手机 + mCamera.setParameters(mParameters); + } catch (Exception e) { + isCanUse = false; + } + if (mCamera != null) { + try { + mCamera.release(); + } catch (Exception e) { + e.printStackTrace(); + return isCanUse; + } + } + return isCanUse; + } + + /** + * 录音是否可用 + * 返回true 表示可以使用 返回false表示不可以使用 + */ + public static boolean isVoicePermission() { + AudioRecord record = null; + try { + record = new AudioRecord(MediaRecorder.AudioSource.MIC, 22050, + AudioFormat.CHANNEL_CONFIGURATION_MONO, + AudioFormat.ENCODING_PCM_16BIT, + AudioRecord.getMinBufferSize(22050, + AudioFormat.CHANNEL_CONFIGURATION_MONO, + AudioFormat.ENCODING_PCM_16BIT)); + record.startRecording(); + int recordingState = record.getRecordingState(); + if (recordingState == AudioRecord.RECORDSTATE_STOPPED) { + return false; + } + //第一次 为true时,先释放资源,在进行一次判定 + //************ + record.release(); + record = new AudioRecord(MediaRecorder.AudioSource.MIC, 22050, + AudioFormat.CHANNEL_CONFIGURATION_MONO, + AudioFormat.ENCODING_PCM_16BIT, + AudioRecord.getMinBufferSize(22050, + AudioFormat.CHANNEL_CONFIGURATION_MONO, + AudioFormat.ENCODING_PCM_16BIT)); + record.startRecording(); + int recordingState1 = record.getRecordingState(); + if (recordingState1 == AudioRecord.RECORDSTATE_STOPPED) { + } + //************** + //如果两次都是true, 就返回true 原因未知 + return true; + } catch (Exception e) { + return false; + } finally { + if (record != null) { + record.release(); + } + } + + } + + /** + * 联系人列表是否可用 + * 返回true 表示可以使用 返回false表示不可以使用 + */ + public static boolean isContactsListPermission(Context context) { + Cursor cursor = null; + try { + cursor = context.getContentResolver().query( + ContactsContract.CommonDataKinds.Phone.CONTENT_URI, + null, null, null, null); + if (cursor != null && cursor.moveToFirst()) { + return true; + } else { + return false; + } + } catch (Exception e) { + return false; + } finally { + if (cursor != null) { + cursor.close(); + } + } + } + + /** + * 是否有读写权限 + * + * @return + */ + public static boolean isWritePermission() { + boolean isCanUser = true; + File file = Environment.getExternalStorageDirectory(); + File newfile = new File(file, "1.txt"); + FileWriter fw = null; + try { + fw = new FileWriter(newfile); + fw.flush(); + fw.write("123"); + isCanUser = true; + } catch (Exception e) { + isCanUser = false; + } finally { + if (fw != null) { + try { + fw.close(); + isCanUser = true; + } catch (IOException e) { + isCanUser = false; + } + } + } + return isCanUser; + } + + public static boolean isSmsPermission(Context context) { + String SMS_URI_ALL = "content://sms/"; + Cursor cursor = null; + try { + Uri uri = Uri.parse(SMS_URI_ALL); + String[] projection = new String[]{"_id", "address", "person", + "body", "date", "type"}; + cursor = context.getContentResolver().query(uri, projection, null, + null, "date desc"); // 获取手机内部短信 + //这里需要注意,当没有权限时拿到的count可能是0,也许记录被删除了,这里需要注意下! + if (cursor != null && cursor.moveToFirst()) { + return true; + } else { + return false; + } + } catch (Exception ex) { + return false; + } finally { + if (cursor != null) { + cursor.close(); + } + } + } + +} diff --git a/app/src/main/java/com/maning/gankmm/utils/PermissionManager.java b/app/src/main/java/com/maning/gankmm/utils/PermissionManager.java new file mode 100644 index 0000000..6dea525 --- /dev/null +++ b/app/src/main/java/com/maning/gankmm/utils/PermissionManager.java @@ -0,0 +1,162 @@ +package com.maning.gankmm.utils; + +import android.app.Activity; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.net.Uri; +import android.os.Build; +import android.provider.Settings; + +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.FragmentActivity; + +import com.hjq.permissions.OnPermissionCallback; +import com.hjq.permissions.XXPermissions; + +import java.util.List; +import java.util.Random; + + +/** + * @author : maning + * @date : 2020-10-20 + * @desc : 权限管理,自由替换三方权限管理库 + */ +public class PermissionManager { + + public interface OnPermissionCallback { + void onGranted(); + + void onDenied(boolean never); + } + + private FragmentActivity mActivity; + private OnPermissionCallback callback; + private boolean auto2setting = false; + + private PermissionManager(FragmentActivity activity) { + mActivity = activity; + } + + public static PermissionManager with(FragmentActivity activity) { + return new PermissionManager(activity); + } + + /** + * 是否自动跳转设置页面 + * 当用户选择了不在询问,就自动跳转应用详情页面 + */ + public PermissionManager auto2setting(boolean auto2setting) { + this.auto2setting = auto2setting; + return this; + } + + public PermissionManager callback(OnPermissionCallback callback) { + this.callback = callback; + return this; + } + + public void request(String... permissions) { + requestWithXXPermission(permissions); + } + + private void requestWithXXPermission(String[] permissions) { + XXPermissions.with(mActivity) + .permission(permissions) + .request(new com.hjq.permissions.OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + if (callback == null) { + return; + } + if (all) { + callback.onGranted(); + } else { + callback.onDenied(false); + } + } + + @Override + public void onDenied(List permissions, boolean never) { + if (callback == null) { + return; + } + if (never) { + //被永久拒绝授权 + if (auto2setting) { + openAppSettingPage(mActivity); + } + } + callback.onDenied(never); + } + }); + } + + /** + * 打开应用详情页面 + * + * @param activity + */ + public static int openAppSettingPage(Activity activity) { + int randomRequestCode = getRandomRequestCode(); + Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + intent.setData(Uri.parse("package:" + activity.getPackageName())); + activity.startActivityForResult(intent, randomRequestCode); + return randomRequestCode; + } + + /** + * 检查权限是否被赋予 + */ + public static boolean isGranted(Activity activity, String permission) { + if (!isAndroid6()) { + return true; + } + return activity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED; + } + + /** + * 获得随机的 RequestCode + */ + private static int getRandomRequestCode() { + // 请求码必须在 2 的 16 次方以内 + return new Random().nextInt((int) Math.pow(2, 16)); + } + + /** + * 是否是 Android 6.0 及以上版本 + */ + private static boolean isAndroid6() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; + } + + /** + * 开启权限页面 + * + * @param context + * @param str + */ + public static void showPermissionDialog(Activity context, String str) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(str); + builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + builder.setPositiveButton("前往", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + Uri uri = Uri.fromParts("package", context.getApplicationContext().getPackageName(), null); + intent.setData(uri); + context.startActivityForResult(intent, 0); + } + }); + builder.setCancelable(false); + builder.create().show(); + } + +} diff --git a/app/src/main/java/com/maning/gankmm/utils/PermissionUtils.java b/app/src/main/java/com/maning/gankmm/utils/PermissionUtils.java deleted file mode 100644 index d6c0f34..0000000 --- a/app/src/main/java/com/maning/gankmm/utils/PermissionUtils.java +++ /dev/null @@ -1,412 +0,0 @@ -package com.maning.gankmm.utils; - -import android.content.Context; -import android.content.Intent; -import android.database.Cursor; -import android.hardware.Camera; -import android.media.AudioFormat; -import android.media.AudioRecord; -import android.media.MediaRecorder; -import android.net.Uri; -import android.os.Build; -import android.os.Environment; -import android.provider.ContactsContract; -import android.provider.Settings; - -import com.socks.library.KLog; -import com.yanzhenjie.permission.Action; -import com.yanzhenjie.permission.AndPermission; -import com.yanzhenjie.permission.Permission; -import com.yanzhenjie.permission.Rationale; -import com.yanzhenjie.permission.RequestExecutor; -import com.yanzhenjie.permission.SettingService; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.List; - -/** - *

- *     author : maning
- *     e-mail : xxx@xx
- *     time   : 2018/01/30
- *     desc   : 权限工具:适配5.0之下和之上
- *     version: 1.0
- * 
- */ -public class PermissionUtils { - - /** - * 打开应用详情页面intent - */ - public static void gotoAppDetailSettingIntent(Context context) { - // vivo 点击设置图标>加速白名单>我的app - // 点击软件管理>软件管理权限>软件>我的app>信任该软件 - Intent appIntent = context.getPackageManager().getLaunchIntentForPackage("com.iqoo.secure"); - if (appIntent != null) { - context.startActivity(appIntent); - return; - } - // oppo 点击设置图标>应用权限管理>按应用程序管理>我的app>我信任该应用 - // 点击权限隐私>自启动管理>我的app - appIntent = context.getPackageManager().getLaunchIntentForPackage("com.oppo.safe"); - if (appIntent != null) { - context.startActivity(appIntent); - return; - } - //其他 - Intent intent = new Intent(); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); - intent.setData(Uri.fromParts("package", context.getPackageName(), null)); - context.startActivity(intent); - } - - /** - * 系统设置界面 - * - * @param context - */ - public static void SystemConfig(Context context) { - Intent intent = new Intent(Settings.ACTION_SETTINGS); - context.startActivity(intent); - } - - /** - * 判断是不是Android 6.0 以上的版本 - * - * @return - */ - public static boolean isAndroidM() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - return true; - } - return false; - } - - public interface PermissionCallBack { - void onGranted(); - - void onDenied(); - } - - public static void checkWritePermission(final Context context, final PermissionCallBack permissionCallBack) { - //6.0及以上 - if (isAndroidM()) { - //请求权限 - AndPermission.with(context) - .permission(Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE) - .onGranted(new Action() { - @Override - public void onAction(List permissions) { - permissionCallBack.onGranted(); - } - }) - .onDenied(new Action() { - @Override - public void onAction(List permissions) { - //一直被拒绝弹框给用户 - if (AndPermission.hasAlwaysDeniedPermission(context, permissions)) { - KLog.i("AndPermission----onDenied--hasAlwaysDeniedPermission"); - final SettingService settingService = AndPermission.permissionSetting(context); - //弹框给用户去设置页面 - DialogUtils.showMyDialog(context, - "权限提醒", - "为保证您正常地使用此功能,需要到手机设置中开启您的存储权限,去开启。", - "去开启", - "取消", - new DialogUtils.OnDialogClickListener() { - @Override - public void onConfirm() { - try { - settingService.execute(); - } catch (Exception e) { - gotoAppDetailSettingIntent(context); - } - } - - @Override - public void onCancel() { - //取消 - permissionCallBack.onDenied(); - } - }); - - } else { - KLog.i("AndPermission----onDenied"); - permissionCallBack.onDenied(); - } - } - }) - .start(); - } else { - if (isWritePermission()) { - permissionCallBack.onGranted(); - } else { - permissionCallBack.onDenied(); - } - } - } - - /** - * 检查相机权限 - * - * @param context - * @param permissionCallBack - */ - public static void checkCameraPermission(final Context context, final PermissionCallBack permissionCallBack) { - //请求权限 - if (isAndroidM()) { - AndPermission.with(context) - .permission(Permission.CAMERA) - .onGranted(new Action() { - @Override - public void onAction(List permissions) { - permissionCallBack.onGranted(); - } - }) - .onDenied(new Action() { - @Override - public void onAction(List permissions) { - //一直被拒绝弹框给用户 - if (AndPermission.hasAlwaysDeniedPermission(context, permissions)) { - KLog.i("AndPermission----onDenied--hasAlwaysDeniedPermission"); - final SettingService settingService = AndPermission.permissionSetting(context); - //弹框给用户去设置页面 - DialogUtils.showMyDialog(context, - "权限提醒", - "为保证您正常地使用此功能,需要到手机设置中开启您的相机权限,去开启。", - "去开启", - "取消", - new DialogUtils.OnDialogClickListener() { - @Override - public void onConfirm() { - try { - settingService.execute(); - } catch (Exception e) { - gotoAppDetailSettingIntent(context); - } - } - - @Override - public void onCancel() { - permissionCallBack.onDenied(); - } - }); - } else { - KLog.i("AndPermission----onDenied"); - permissionCallBack.onDenied(); - } - } - }) - .start(); - } else { - boolean cameraPermission = isCameraPermission(); - if (!cameraPermission) { - permissionCallBack.onDenied(); - return; - } - permissionCallBack.onGranted(); - } - } - - - public static void checkLocationPermission(final Context context, final PermissionCallBack permissionCallBack) { - AndPermission.with(context) - .permission(Permission.ACCESS_FINE_LOCATION) - .onGranted(new Action() { - @Override - public void onAction(List permissions) { - KLog.i("AndPermission----onGranted"); - permissionCallBack.onGranted(); - } - }) - .onDenied(new Action() { - @Override - public void onAction(List permissions) { - //一直被拒绝弹框给用户 - if (AndPermission.hasAlwaysDeniedPermission(context, permissions)) { - KLog.i("AndPermission----onDenied--hasAlwaysDeniedPermission"); - final SettingService settingService = AndPermission.permissionSetting(context); - //弹框给用户去设置页面 - DialogUtils.showMyDialog(context, - "权限提醒", - "为保证您正常地使用此功能,需要到手机设置中开启您的定位权限,去开启。", - "去开启", - "取消", - new DialogUtils.OnDialogClickListener() { - @Override - public void onConfirm() { - try { - settingService.execute(); - } catch (Exception e) { - gotoAppDetailSettingIntent(context); - } - } - - @Override - public void onCancel() { - permissionCallBack.onDenied(); - } - }); - } else { - KLog.i("AndPermission----onDenied"); - permissionCallBack.onDenied(); - } - } - }) - .start(); - } - - - //--------------------6.0以下权限处理------------------------- - - /** - * 相机是否可用 - * 返回true 表示可以使用 返回false表示不可以使用 - */ - private static boolean isCameraPermission() { - boolean isCanUse = true; - Camera mCamera = null; - try { - mCamera = Camera.open(); - Camera.Parameters mParameters = mCamera.getParameters(); //针对魅族手机 - mCamera.setParameters(mParameters); - } catch (Exception e) { - isCanUse = false; - } - if (mCamera != null) { - try { - mCamera.release(); - } catch (Exception e) { - e.printStackTrace(); - return isCanUse; - } - } - return isCanUse; - } - - /** - * 录音是否可用 - * 返回true 表示可以使用 返回false表示不可以使用 - */ - private static boolean isVoicePermission() { - AudioRecord record = null; - try { - record = new AudioRecord(MediaRecorder.AudioSource.MIC, 22050, - AudioFormat.CHANNEL_CONFIGURATION_MONO, - AudioFormat.ENCODING_PCM_16BIT, - AudioRecord.getMinBufferSize(22050, - AudioFormat.CHANNEL_CONFIGURATION_MONO, - AudioFormat.ENCODING_PCM_16BIT)); - record.startRecording(); - int recordingState = record.getRecordingState(); - if (recordingState == AudioRecord.RECORDSTATE_STOPPED) { - return false; - } - //第一次 为true时,先释放资源,在进行一次判定 - //************ - record.release(); - record = new AudioRecord(MediaRecorder.AudioSource.MIC, 22050, - AudioFormat.CHANNEL_CONFIGURATION_MONO, - AudioFormat.ENCODING_PCM_16BIT, - AudioRecord.getMinBufferSize(22050, - AudioFormat.CHANNEL_CONFIGURATION_MONO, - AudioFormat.ENCODING_PCM_16BIT)); - record.startRecording(); - int recordingState1 = record.getRecordingState(); - if (recordingState1 == AudioRecord.RECORDSTATE_STOPPED) { - } - //************** - //如果两次都是true, 就返回true 原因未知 - return true; - } catch (Exception e) { - return false; - } finally { - if (record != null) { - record.release(); - } - } - - } - - /** - * 联系人列表是否可用 - * 返回true 表示可以使用 返回false表示不可以使用 - */ - private static boolean isContactsListPermission(Context context) { - Cursor cursor = null; - try { - cursor = context.getContentResolver().query( - ContactsContract.CommonDataKinds.Phone.CONTENT_URI, - null, null, null, null); - if (cursor != null && cursor.moveToFirst()) { - return true; - } else { - return false; - } - } catch (Exception e) { - return false; - } finally { - if (cursor != null) { - cursor.close(); - } - } - } - - /** - * 是否有读写权限 - * - * @return - */ - private static boolean isWritePermission() { - boolean isCanUser = true; - File file = Environment.getExternalStorageDirectory(); - File newfile = new File(file, "1.txt"); - FileWriter fw = null; - try { - fw = new FileWriter(newfile); - fw.flush(); - fw.write("123"); - isCanUser = true; - } catch (Exception e) { - isCanUser = false; - } finally { - if (fw != null) { - try { - fw.close(); - isCanUser = true; - } catch (IOException e) { - isCanUser = false; - } - } - } - return isCanUser; - } - - private static boolean isSmsPermission(Context context) { - String SMS_URI_ALL = "content://sms/"; - Cursor cursor = null; - try { - Uri uri = Uri.parse(SMS_URI_ALL); - String[] projection = new String[]{"_id", "address", "person", - "body", "date", "type"}; - cursor = context.getContentResolver().query(uri, projection, null, - null, "date desc"); // 获取手机内部短信 - //这里需要注意,当没有权限时拿到的count可能是0,也许记录被删除了,这里需要注意下! - if (cursor != null && cursor.moveToFirst()) { - return true; - } else { - return false; - } - } catch (Exception ex) { - return false; - } finally { - if (cursor != null) { - cursor.close(); - } - } - } - -} diff --git a/app/src/main/java/com/maning/gankmm/utils/ZxingScanUtils.java b/app/src/main/java/com/maning/gankmm/utils/ZxingScanUtils.java index 7e8f8b9..c12aaa0 100644 --- a/app/src/main/java/com/maning/gankmm/utils/ZxingScanUtils.java +++ b/app/src/main/java/com/maning/gankmm/utils/ZxingScanUtils.java @@ -1,8 +1,10 @@ package com.maning.gankmm.utils; -import android.app.Activity; +import android.Manifest; import android.content.Intent; +import androidx.fragment.app.FragmentActivity; + import com.google.zxing.client.android.MNScanManager; import com.google.zxing.client.android.model.MNScanConfig; import com.google.zxing.client.android.other.MNScanCallback; @@ -17,50 +19,62 @@ public class ZxingScanUtils { private static final String COLOR_MAIN = "#62e203"; - public static void open(final Activity activity) { - //自定义扫描 - MNScanConfig scanConfig = new MNScanConfig.Builder() - //设置完成震动 - .isShowVibrate(false) - //扫描完成声音 - .isShowBeep(true) - //显示相册功能 - .isShowPhotoAlbum(true) - //显示闪光灯 - .isShowLightController(true) - //自定义文案 - .setScanHintText("请对准二维码/条形码识别") - //扫描线的颜色 - .setScanColor(COLOR_MAIN) - //是否显示缩放控制器 - .isShowZoomController(false) - //扫描线样式 - .setLaserStyle(MNScanConfig.LaserStyle.Line) - //是否全屏范围扫描 - .setFullScreenScan(true) - //二维码标记点 - .isShowResultPoint(true) - .setResultPointConfigs(60, 30, 10, "#FFFFFFFF", "#7000A81F") - .builder(); - MNScanManager.startScan(activity, scanConfig, new MNScanCallback() { - @Override - public void onActivityResult(int resultCode, Intent data) { - switch (resultCode) { - case MNScanManager.RESULT_SUCCESS: - String resultSuccess = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS); - //扫描成功 - //跳转到扫码结果页面 - ScanResultActivity.open(activity, resultSuccess); - break; - case MNScanManager.RESULT_FAIL: - String resultError = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_ERROR); - MyToast.showShortToast(resultError); - break; - case MNScanManager.RESULT_CANCLE: - break; - } - } - }); + public static void open(final FragmentActivity activity) { + PermissionManager.with(activity) + .callback(new PermissionManager.OnPermissionCallback() { + @Override + public void onGranted() { + //自定义扫描 + MNScanConfig scanConfig = new MNScanConfig.Builder() + //设置完成震动 + .isShowVibrate(false) + //扫描完成声音 + .isShowBeep(true) + //显示相册功能 + .isShowPhotoAlbum(true) + //显示闪光灯 + .isShowLightController(true) + //自定义文案 + .setScanHintText("请对准二维码/条形码识别") + //扫描线的颜色 + .setScanColor(COLOR_MAIN) + //是否显示缩放控制器 + .isShowZoomController(false) + //扫描线样式 + .setLaserStyle(MNScanConfig.LaserStyle.Line) + //是否全屏范围扫描 + .setFullScreenScan(true) + //二维码标记点 + .isShowResultPoint(true) + //单位dp + .setResultPointConfigs(30, 30, 3, "#FFFFFFFF", "#7000A81F") + .builder(); + MNScanManager.startScan(activity, scanConfig, new MNScanCallback() { + @Override + public void onActivityResult(int resultCode, Intent data) { + switch (resultCode) { + case MNScanManager.RESULT_SUCCESS: + String resultSuccess = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS); + //扫描成功 + //跳转到扫码结果页面 + ScanResultActivity.open(activity, resultSuccess); + break; + case MNScanManager.RESULT_FAIL: + String resultError = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_ERROR); + MyToast.showShortToast(resultError); + break; + case MNScanManager.RESULT_CANCLE: + break; + } + } + }); + } + + @Override + public void onDenied(boolean never) { + MyToast.showShortToast("权限被拒绝,无法扫码"); + } + }).request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA); } } diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml index 7fdb52f..4c6b1be 100644 --- a/app/src/main/res/layout/activity_setting.xml +++ b/app/src/main/res/layout/activity_setting.xml @@ -21,6 +21,7 @@ @@ -28,6 +29,7 @@ android:layout_width="match_parent" android:layout_height="44dp" android:layout_marginTop="20dp" + android:visibility="gone" android:background="?item_setting_bg">