AndroidWebview应用程序中启用文件上传功能。
创始人
2024-10-12 03:30:54
0

要在Android Webview应用程序中启用文件上传功能,可以按照以下步骤进行操作:

1.在AndroidManifest.xml文件中添加以下代码以获取WRITE_EXTERNAL_STORAGE权限:

2.在Webview设置中启用JavaScript:

webView.getSettings().setJavaScriptEnabled(true);

3.为Webview设置WebChromeClient:

webView.setWebChromeClient(new WebChromeClient() { //文件选择器数据 public void openFileChooser(ValueCallback uploadMsg) {

    //创建包含传递文件URI的意图
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*");

    //启动文件选择器
    startActivityForResult(Intent.createChooser(intent, "File Chooser"), FILECHOOSER_RESULTCODE);
}

// For Android  >= 3.0
public void openFileChooser(ValueCallback uploadMsg, String acceptType) {
    openFileChooser(uploadMsg, acceptType, "");
}

// For Android  >= 4.1
public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) {
    mUploadMessage = uploadMsg;
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*");
    startActivityForResult(Intent.createChooser(intent, "File Chooser"), FILECHOOSER_RESULTCODE);
}

// For Android > 5.0
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
    mFilePathCallback = filePathCallback;
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*");
    startActivityForResult(Intent.createChooser(intent, "File Chooser"), FILECHOOSER_RESULTCODE);
    return true;
}

});

4.在onActivityResult方法中处理文件选择器意图:

@Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == FILECHOOSER_RESULTCODE) { if (resultCode == Activity.RESULT_OK && intent

相关内容

热门资讯

wpk模拟器是什么!wepok... wpk模拟器是什么!wepoker-h5下载(透视)脚本-切实有挂存在有挂1、用户打开应用后不用登录...
透视透视!werplan辅助软... 透视透视!werplan辅助软件(透视)wpk透视辅助,教程总结(有挂方法)-哔哩哔哩1、该软件可以...
wpk俱乐部辅助器!epoke... wpk俱乐部辅助器!epoker底牌透视(透视)app-一贯揭幕真的是有挂所有人都在同一条线上,像星...
透视科普!pokemmo手机版... 透视科普!pokemmo手机版脚本(透视)wepoker私人局透视插件,教程指南书(有挂技巧)-哔哩...
智星德州插件怎么下载!hhpo... 智星德州插件怎么下载!hhpoker德州真的假的(透视)app-本来分享是真的挂1、操作简单,无需智...
透视专业!wepokerplu... 透视专业!wepokerplus辅助(透视)wpk透视是真的吗,教程教材(有挂攻略)-哔哩哔哩1、每...
WePOker有没有透视方法!... WePOker有没有透视方法!aapoker怎么设置提高好牌几率(透视)技巧-总是了解真的是有挂1、...
透视揭露!wepokerplu... 透视揭露!wepokerplus开挂(透视)wpk透视最怕三个东西,教程法子(有挂头条)-哔哩哔哩1...
hhpkoer辅助挂是真的吗!... hhpkoer辅助挂是真的吗!wepoker辅助透视软件(透视)方法-其实专业存在有挂在进入hhpk...
透视关于!hhpkoer辅助器... 透视关于!hhpkoer辅助器视频(透视)hhpoker为什么一直输,教程教材(有挂头条)-哔哩哔哩...