技术经验谈 技术经验谈
首页
  • 最佳实践

    • 抓包
    • 数据库操作
  • ui

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • 《Git》
    • TypeScript
    • JS设计模式总结
  • 总纲
  • 整体开发框架
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

hss01248

一号线程序员
首页
  • 最佳实践

    • 抓包
    • 数据库操作
  • ui

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • 《Git》
    • TypeScript
    • JS设计模式总结
  • 总纲
  • 整体开发框架
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 学习资料

  • 技术选型

  • 要点

    • dart语言核心要点
    • 工程化

      • flutter依赖管理
      • flutter代码模板优化和禁用.android文件夹刷新
      • flutter客户端项目适配web做的一些工作
      • web跨域问题终结者
      • flutter编译流程修改
      • flutter工程的模块化架构
      • flutter web编译瘦身
      • webview_flutter官方插件的增强-对inputfile和权限请求的支持
    • flutter异步
    • flutter工程化
    • flutter存储相关
    • flutter状态管理
    • flutter网络框架以及相关要点
    • flutter图片相关
    • flutter可观测性和调试
    • flutter插件开发
    • flutter路由管理
    • 遇到的问题
  • 经验

  • flutter
  • 要点
  • 工程化
hss01248
2023-06-29

webview_flutter官方插件的增强-对inputfile和权限请求的支持

# webview_flutter官方插件的增强-Android上对inputfile和权限请求的支持

插件升级到最新版本(较老的版本上没有实现onPermissionRequest回调,最新的版本上没有实现onGeolocationPermissionsShowPrompt回调).

使用aop切入插件的Android代码,实现对应的onShowFileChooser和onPermissionRequest方法.

如下所示:

@Aspect
public class FlutterWebChromeClientAspect {

    private static final String TAG = "WebChromeClientAspect";


    //public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams)
    @Around("execution(* io.flutter.plugins.webviewflutter.WebChromeClientHostApiImpl.WebChromeClientImpl.onShowFileChooser(..))")
    public Object onShowFileChooser(ProceedingJoinPoint joinPoint) throws Throwable {
        WebView webView = (WebView) joinPoint.getArgs()[0];
        ValueCallback<Uri[]> filePathCallback = (ValueCallback) joinPoint.getArgs()[1];
        WebChromeClient.FileChooserParams fileChooserParams = (WebChromeClient.FileChooserParams) joinPoint.getArgs()[2];

        LogMethodAspect.logBefore(true, TAG, joinPoint, new LogMethodAspect.IBefore() {
            @Override
            public void before(JoinPoint joinPoin, String desc) {
                LogMethodAspect.IBefore.super.before(joinPoin, desc);
            }
        });

        return new FileChooseImpl().onShowFileChooser(webView, filePathCallback, fileChooserParams);
    }


    //public void onPermissionRequest(PermissionRequest request)
    @Around("execution(* io.flutter.plugins.webviewflutter.WebChromeClientHostApiImpl.WebChromeClientImpl.onPermissionRequest(..))")
    public void onPermissionRequest(ProceedingJoinPoint joinPoint) throws Throwable {
        PermissionRequest request = (PermissionRequest) joinPoint.getArgs()[0];

        LogMethodAspect.logBefore(true, TAG, joinPoint, new LogMethodAspect.IBefore() {
            @Override
            public void before(JoinPoint joinPoin, String desc) {
                LogMethodAspect.IBefore.super.before(joinPoin, desc);
            }
        });
         new JsPermissionImpl().onPermissionRequest(request);
    }

    //public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback)
    @Around("execution(* io.flutter.plugins.webviewflutter.WebChromeClientHostApiImpl.WebChromeClientImpl.onGeolocationPermissionsShowPrompt(..))")
    public void onGeolocationPermissionsShowPrompt(ProceedingJoinPoint joinPoint) throws Throwable {
        String origin = (String) joinPoint.getArgs()[0];
        GeolocationPermissions.Callback callback = (GeolocationPermissions.Callback) joinPoint.getArgs()[1];
        LogMethodAspect.logBefore(true, TAG, joinPoint, new LogMethodAspect.IBefore() {
            @Override
            public void before(JoinPoint joinPoin, String desc) {
                LogMethodAspect.IBefore.super.before(joinPoin, desc);
            }
        });
        new JsPermissionImpl().onGeolocationPermissionsShowPrompt(origin,callback);
    }


}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

此处JsPermissionImpl,FileChooseImpl两个类引用自:

   api 'com.github.hss01248.utilcodeEnhance:media:1.2.7'
   api 'com.github.hss01248.utilcodeEnhance:baseWebview:1.2.7'
   api 'com.github.hss01248.StartActivityResult:activityresult:1.1.7'
1
2
3

其内部对input file标签,权限申请做了非常完善的适配,见webview文件选择-input-file适配 (opens new window)

然后按aspectjx的配置要求配置相关包名即可.

便捷使用方式: 脚本一键引入:

apply from: 'https://raw.githubusercontent.com/hss01248/flipperUtil/dev/remote3.gradle
1

并在gradle.properties里配置:

use_aspectjx_in_release=true
1
编辑 (opens new window)
上次更新: 2023/06/29, 14:58:50
flutter web编译瘦身
flutter异步

← flutter web编译瘦身 flutter异步→

最近更新
01
截图后的自动压缩工具
12-27
02
图片视频文件根据exif批量重命名
12-27
03
chatgpt图片识别描述功能
02-20
更多文章>
Theme by Vdoing | Copyright © 2020-2025 | 粤ICP备20041795号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式