Justson / AgentWeb

AgentWeb is a powerful library based on Android WebView.
https://www.jianshu.com/p/fc7909e24178
Apache License 2.0
9.27k stars 1.64k forks source link

有没有好心人适配下android13 无法选择图片 和调起摄像头 #1048

Closed lee-you closed 11 months ago

lee-you commented 1 year ago

有没有好心人适配下android13 无法选择图片文件 和调起摄像头

AivanUy commented 1 year ago

只能自己修改源码了: 1、把源码下下来,targetSdkVersion compileSdk 都改成33 2、把废除的 方法注释掉 3、修改 public class FileChooser 类: onCameraAction(); 方法 和 fileChooser() 方法 image image

权限判断:

  //权限请求 支持Androidx https://github.com/guolindev/PermissionX
    //noinspection UseTomlInstead
    implementation 'com.guolindev.permissionx:permissionx:1.7.1'
    private void checkPicturePermission(){
        ArrayList<String> requestList = new ArrayList<>();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            requestList.add(Manifest.permission.READ_MEDIA_IMAGES);
            requestList.add(Manifest.permission.READ_MEDIA_AUDIO);
            requestList.add(Manifest.permission.READ_MEDIA_VIDEO);
        } else {
            requestList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
            requestList.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        }
        PermissionX.init((FragmentActivity) mActivity).permissions().request(new RequestCallback() {
            @Override
            public void onResult(boolean allGranted, @NonNull List<String> grantedList, @NonNull List<String> deniedList) {
                touchOffFileChooserAction();
            }
        });
    }
private void checkCameraPermission(){
        ArrayList<String> requestList = new ArrayList<>();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            requestList.add(Manifest.permission.READ_MEDIA_IMAGES);
            requestList.add(Manifest.permission.READ_MEDIA_AUDIO);
            requestList.add(Manifest.permission.READ_MEDIA_VIDEO);
            requestList.add(Manifest.permission.CAMERA);
        } else {
            requestList.add(Manifest.permission.CAMERA);
            requestList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
            requestList.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        }
        PermissionX.init((FragmentActivity) mActivity).permissions().request(new RequestCallback() {
            @Override
            public void onResult(boolean allGranted, @NonNull List<String> grantedList, @NonNull List<String> deniedList) {
                openCameraAction();
            }
        });
    }
zzl313703419 commented 1 year ago

牛啊 犹如及时雨一般 在我放弃时候出现了

zzl313703419 commented 1 year ago

修改完后如何引用呢 谢谢

AivanUy commented 1 year ago

就普通库模块引用呀

Smail-cai commented 1 year ago

兄弟,权限列表放进去啊,搞得我一直试没效果,唉 PermissionX.init((FragmentActivity) mActivity).permissions(requestList).request(new RequestCallback() { @Override public void onResult(boolean allGranted, @NonNull List grantedList, @NonNull List deniedList) { touchOffFileChooserAction(); } });

Justson commented 1 year ago

只能自己修改源码了: 1、把源码下下来,targetSdkVersion compileSdk 都改成33 2、把废除的 方法注释掉 3、修改 public class FileChooser 类: onCameraAction(); 方法 和 fileChooser() 方法 image image

权限判断:

  //权限请求 支持Androidx https://github.com/guolindev/PermissionX
    //noinspection UseTomlInstead
    implementation 'com.guolindev.permissionx:permissionx:1.7.1'
    private void checkPicturePermission(){
        ArrayList<String> requestList = new ArrayList<>();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            requestList.add(Manifest.permission.READ_MEDIA_IMAGES);
            requestList.add(Manifest.permission.READ_MEDIA_AUDIO);
            requestList.add(Manifest.permission.READ_MEDIA_VIDEO);
        } else {
            requestList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
            requestList.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        }
        PermissionX.init((FragmentActivity) mActivity).permissions().request(new RequestCallback() {
            @Override
            public void onResult(boolean allGranted, @NonNull List<String> grantedList, @NonNull List<String> deniedList) {
                touchOffFileChooserAction();
            }
        });
    }
private void checkCameraPermission(){
     ArrayList<String> requestList = new ArrayList<>();
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
         requestList.add(Manifest.permission.READ_MEDIA_IMAGES);
         requestList.add(Manifest.permission.READ_MEDIA_AUDIO);
         requestList.add(Manifest.permission.READ_MEDIA_VIDEO);
         requestList.add(Manifest.permission.CAMERA);
     } else {
         requestList.add(Manifest.permission.CAMERA);
         requestList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
         requestList.add(Manifest.permission.READ_EXTERNAL_STORAGE);
     }
     PermissionX.init((FragmentActivity) mActivity).permissions().request(new RequestCallback() {
         @Override
         public void onResult(boolean allGranted, @NonNull List<String> grantedList, @NonNull List<String> deniedList) {
             openCameraAction();
         }
     });
 }

别用PermissionX,欢迎提个pr来哈

121104115wyb commented 1 year ago

这种方式改动更小(前几步骤和二楼一致) 1.targetSdkVersion 33 2.compileSdkVersion 33 3.下载 agentweb 和 filechooser 代码使用module方式导入项目中,升级到33后会有websetting 属性不可用,注释掉即可

image

4.build.gradle中加入依赖

    //webView
//    api rootProject.ext.agentweb
//    api rootProject.ext.agentwebfilechooser
    //依赖本地
    api project(path: ':agentweb')
    implementation project(path: ':filechooser')

在AgentWebPermissions 中定义了要申请的权限,我们改动这里面的代码即可,其它不需要变动:

public class AgentWebPermissions {
    public static final String[] CAMERA;
    public static final String[] LOCATION;
    public static final String[] STORAGE;
    public static final String ACTION_CAMERA = "Camera";
    public static final String ACTION_LOCATION = "Location";
    public static final String ACTION_STORAGE = "Storage";

    static {
        CAMERA = new String[]{
                Manifest.permission.CAMERA};

        LOCATION = new String[]{
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.ACCESS_COARSE_LOCATION};
        //这里按照需要添加
        if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
            STORAGE = new String[]{
                    Manifest.permission.READ_MEDIA_IMAGES};
        } else {
            STORAGE = new String[]{
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE};
        }
    }
}

最后 manifest 文件权限不要忘记添加

使用android 13 手机测试没有问题!!!

Justson commented 1 year ago

这种方式改动更小(前几步骤和二楼一致) 1.targetSdkVersion 33 2.compileSdkVersion 33 3.下载 agentweb 和 filechooser 代码使用module方式导入项目中,升级到33后会有websetting 属性不可用,注释掉即可

image

4.build.gradle中加入依赖

    //webView
//    api rootProject.ext.agentweb
//    api rootProject.ext.agentwebfilechooser
    //依赖本地
    api project(path: ':agentweb')
    implementation project(path: ':filechooser')

在AgentWebPermissions 中定义了要申请的权限,我们改动这里面的代码即可,其它不需要变动:

public class AgentWebPermissions {
    public static final String[] CAMERA;
    public static final String[] LOCATION;
    public static final String[] STORAGE;
    public static final String ACTION_CAMERA = "Camera";
    public static final String ACTION_LOCATION = "Location";
    public static final String ACTION_STORAGE = "Storage";

    static {
        CAMERA = new String[]{
                Manifest.permission.CAMERA};

        LOCATION = new String[]{
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.ACCESS_COARSE_LOCATION};
        //这里按照需要添加
        if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
            STORAGE = new String[]{
                    Manifest.permission.READ_MEDIA_IMAGES};
        } else {
            STORAGE = new String[]{
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE};
        }
    }
}

最后 manifest 文件权限不要忘记添加

使用android 13 手机测试没有问题!!!

欢迎pr

VectorWen commented 12 months ago

好像没有那么复杂,只需要改一下AgentWebPermissions

public class AgentWebPermissions {
    public static final String[] CAMERA;
    public static final String[] LOCATION;
    public static final String[] STORAGE;
    public static final String ACTION_CAMERA = "Camera";
    public static final String ACTION_LOCATION = "Location";
    public static final String ACTION_STORAGE = "Storage";

    static {
        CAMERA = new String[]{
                Manifest.permission.CAMERA};
        LOCATION = new String[]{
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.ACCESS_COARSE_LOCATION};

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            STORAGE = new String[]{
                    Manifest.permission.READ_MEDIA_IMAGES,
                    Manifest.permission.READ_MEDIA_AUDIO,
                    Manifest.permission.READ_MEDIA_VIDEO
            };
        } else {
            STORAGE = new String[]{
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE};

        }
    }
}
Justson commented 11 months ago

已适配v5.1.1-androidx