Skip to content

Commit

Permalink
更新演示App
Browse files Browse the repository at this point in the history
  • Loading branch information
jenly1314 committed Mar 4, 2024
1 parent 8f5dc4e commit e26dfc2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 46 deletions.
Binary file modified app/release/app-release.apk
Binary file not shown.
5 changes: 0 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
52 changes: 11 additions & 41 deletions app/src/main/java/com/king/zxing/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,25 @@
*/
package com.king.zxing.app;

import android.Manifest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.ImageDecoder;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;

import com.king.camera.scan.CameraScan;
import com.king.camera.scan.util.LogUtils;
import com.king.camera.scan.util.PermissionUtils;
import com.king.zxing.util.CodeUtils;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;

/**
* 扫码示例
*/
Expand All @@ -51,8 +45,6 @@ public class MainActivity extends AppCompatActivity {
public static final int REQUEST_CODE_SCAN = 0x01;
public static final int REQUEST_CODE_PHOTO = 0x02;

public static final int REQUEST_CODE_READ_EXTERNAL_STORAGE = 0x99;

private Toast toast;

private ExecutorService executor = Executors.newSingleThreadExecutor();
Expand Down Expand Up @@ -82,10 +74,11 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}

private void showToast(String text) {
if(toast != null) {
if (toast != null) {
toast.cancel();
}
toast = Toast.makeText(this, text, Toast.LENGTH_SHORT);

toast = Toast.makeText(this, String.valueOf(text), Toast.LENGTH_SHORT);
toast.show();
}

Expand All @@ -108,17 +101,6 @@ private void parsePhoto(Intent data) {

}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == REQUEST_CODE_READ_EXTERNAL_STORAGE && PermissionUtils.requestPermissionsResult(
Manifest.permission.READ_EXTERNAL_STORAGE,
permissions,
grantResults)) {
startPickPhoto();
}
}

private void asyncThread(Runnable runnable) {
executor.execute(runnable);
Expand Down Expand Up @@ -147,24 +129,12 @@ private void startGenerateCodeActivity(boolean isQRCode, String title) {
startActivity(intent);
}

/**
* 点击选择图片识别 - 进行动态权限校验
*/
private void pickPhotoClicked() {
if (PermissionUtils.checkPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
startPickPhoto();
} else {
PermissionUtils.requestPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE, REQUEST_CODE_READ_EXTERNAL_STORAGE);
}
}

/**
* 开始选择图片
*/
private void startPickPhoto() {
Intent pickIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK);
pickIntent.setType("image/*");
startActivityForResult(pickIntent, REQUEST_CODE_PHOTO);
}

Expand All @@ -181,7 +151,7 @@ public void onClick(View v) {
startScan(FullScreenQRCodeScanActivity.class);
break;
case R.id.btnPickPhoto:
pickPhotoClicked();
startPickPhoto();
break;
case R.id.btnGenerateQrCode:
startGenerateCodeActivity(true, ((Button) v).getText().toString());
Expand Down

0 comments on commit e26dfc2

Please sign in to comment.