Przeglądaj źródła

相机权限设置

huyuguo 4 lat temu
rodzic
commit
2eba1d95a9

+ 43 - 59
app/src/main/java/com/electric/chargingpile/activity/MainMapActivity.java

@ -125,9 +125,11 @@ import com.electric.chargingpile.util.LoadingDialog;
125 125
import com.electric.chargingpile.util.Md5Util;
126 126
import com.electric.chargingpile.util.OkHttpUtil;
127 127
import com.electric.chargingpile.util.SharedPreferencesUtil;
128
import com.electric.chargingpile.util.SystemTypeUtil;
128 129
import com.electric.chargingpile.util.ToastUtil;
129 130
import com.electric.chargingpile.util.Util;
130 131
import com.electric.chargingpile.util.ZhanDBHelper;
132
import com.electric.chargingpile.view.AlertDialogCommon;
131 133
import com.electric.chargingpile.view.AlertDialogTwo;
132 134
import com.electric.chargingpile.view.AlertDialogUpdate;
133 135
import com.electric.chargingpile.view.SlideAdView;
@ -1337,7 +1339,6 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1337 1339
        } else {
1338 1340
            iVpoint.setVisibility(View.GONE);
1339 1341
        }
1340
        saveTask();
1341 1342
        if (MainApplication.haveActivity == false) {
1342 1343
            if (MainApplication.isLogin() && MainApplication.isAppStart == true) {
1343 1344
                userChargingCheck();
@ -2501,27 +2502,8 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2501 2502
                }
2502 2503
                if (!MainApplication.isLogin()) {
2503 2504
                    startActivity(new Intent(getApplication(), LoginActivity.class));
2504
                } else if (!cameraTask()) {
2505
                    EasyPermissions.requestPermissions(
2506
                            this,
2507
                            "该功能需要开启摄像头权限,是否前往开启?",
2508
                            RC_CAMERA_PERM,
2509
                            Manifest.permission.CAMERA);
2510 2505
                } else {
2511
                    Intent iintent = new Intent(getApplicationContext(), com.google.zxing.client.android.CaptureActivity.class);
2512
                    iintent.putExtra("url", MainApplication.url);
2513
                    iintent.putExtra("user_id", MainApplication.userId);
2514
                    iintent.putExtra("user_password", MainApplication.userPassword);
2515
                    iintent.putExtra("user_phone", ProfileManager.getInstance().getUsername(getApplicationContext()));
2516
                    LogUtils.e(ProfileManager.getInstance().getUsername(getApplicationContext()));
2517
                    iintent.putExtra("cha", MainMapActivity.cha);
2518
                    iintent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
2519
                    startActivity(iintent);
2520
                    overridePendingTransition(0, 0);
2521
                    if (count == 1) {
2522
                        MobclickAgent.onEvent(getApplicationContext(), "0104");
2523
                        count = 2;
2524
                    }
2506
                    requestCameraPermission();
2525 2507
                }
2526 2508
                break;
2527 2509
@ -2789,16 +2771,27 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2789 2771
2790 2772
    @Override
2791 2773
    public void onPermissionsDenied(int requestCode, List<String> perms) {
2792
        for (String s : perms) {
2793
            LogUtils.e(s);
2794
        }
2795 2774
2796
        if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
2797
            new AppSettingsDialog.Builder(MainMapActivity.this).build().show();
2798
            // TODO add by hyg20200525
2799
//            new AppSettingsDialog.Builder(MainMapActivity.this,
2800
//                    "该功能需要开启摄像头权限,是否前往开启?").build().show();
2775
//        if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
2776
//            new AppSettingsDialog.Builder(MainMapActivity.this).build().show();
2777
//        }
2778
2779
        if (requestCode == RC_CAMERA_PERM) {
2780
            new AlertDialogCommon(MainMapActivity.this).builder()
2781
                    .setMsg("为保证您正常、安全的使用充电桩,需要获取您的相机权限,请允许。")
2782
                    .setPositiveButton("去设置", new View.OnClickListener() {
2783
                        @Override
2784
                        public void onClick(View v) {
2785
                            SystemTypeUtil.goToPermissionManager(MainMapActivity.this);
2786
                        }
2787
                    }).setNegativeButton("取消", new View.OnClickListener() {
2788
                @Override
2789
                public void onClick(View v) {
2790
                    android.os.Process.killProcess(android.os.Process.myPid());
2791
                }
2792
            }).show();
2801 2793
        }
2794
2802 2795
    }
2803 2796
2804 2797
    @Override
@ -2807,10 +2800,6 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2807 2800
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
2808 2801
    }
2809 2802
2810
    private boolean hasCameraPermission() {
2811
        return EasyPermissions.hasPermissions(this, Manifest.permission.CAMERA);
2812
    }
2813
2814 2803
    private boolean isPermissionOK() {
2815 2804
        return EasyPermissions.hasPermissions(this,
2816 2805
                Manifest.permission.CAMERA,
@ -2819,37 +2808,32 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2819 2808
        );
2820 2809
    }
2821 2810
2822
    @AfterPermissionGranted(RC_SAVE_PERM)
2823
    public boolean saveTask() {
2824
        if (isPermissionOK()) {
2825
            // Have permission, do the thing!
2826
//            Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show();
2827
            return true;
2828
        } else {
2829
            // Ask for one permission
2830
//            EasyPermissions.requestPermissions(
2831
//                    this,
2832
//                    "该功能需要开启摄像头权限,是否前往开启?",
2833
//                    RC_CAMERA_PERM,
2834
//                    Manifest.permission.CAMERA);
2835
            return false;
2836
        }
2811
    private boolean hasCameraPermission() {
2812
        return EasyPermissions.hasPermissions(this, Manifest.permission.CAMERA);
2837 2813
    }
2838 2814
2839 2815
    @AfterPermissionGranted(RC_CAMERA_PERM)
2840
    public boolean cameraTask() {
2816
    public void requestCameraPermission() {
2841 2817
        if (hasCameraPermission()) {
2842
            // Have permission, do the thing!
2843
//            Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show();
2844
            return true;
2818
            Intent intent = new Intent(getApplicationContext(), com.google.zxing.client.android.CaptureActivity.class);
2819
            intent.putExtra("url", MainApplication.url);
2820
            intent.putExtra("user_id", MainApplication.userId);
2821
            intent.putExtra("user_password", MainApplication.userPassword);
2822
            intent.putExtra("user_phone", ProfileManager.getInstance().getUsername(getApplicationContext()));
2823
            intent.putExtra("cha", MainMapActivity.cha);
2824
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
2825
            startActivity(intent);
2826
            overridePendingTransition(0, 0);
2827
            if (count == 1) {
2828
                MobclickAgent.onEvent(getApplicationContext(), "0104");
2829
                count = 2;
2830
            }
2845 2831
        } else {
2846
            // Ask for one permission
2847
//            EasyPermissions.requestPermissions(
2848
//                    this,
2849
//                    "该功能需要开启摄像头权限,是否前往开启?",
2850
//                    RC_CAMERA_PERM,
2851
//                    Manifest.permission.CAMERA);
2852
            return false;
2832
            EasyPermissions.requestPermissions(
2833
                    this,
2834
                    "扫码充电需要开启摄像头权限,是否前往开启?",
2835
                    RC_CAMERA_PERM,
2836
                    Manifest.permission.CAMERA);
2853 2837
        }
2854 2838
    }
2855 2839

+ 1 - 1
app/src/main/res/layout/activity_permission_agreement.xml

@ -188,7 +188,7 @@
188 188
                    <TextView
189 189
                        android:layout_width="wrap_content"
190 190
                        android:layout_height="wrap_content"
191
                        android:text="摄像头权限"
191
                        android:text="相机权限"
192 192
                        android:textColor="#444444"
193 193
                        android:textSize="16sp"
194 194
                        android:textStyle="bold" />