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
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
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