Главная > Android > webview input file

webview input file

public class MainActivity extends AppCompatActivity {
    private WebView webView;
    public ValueCallback<Uri[]> uploadMessage;
    public static final int REQUEST_SELECTED_FILE = 100;
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if (requestCode == REQUEST_SELECTED_FILE) {
            if (uploadMessage == null) return;
            uploadMessage.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
            uploadMessage = null;
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        webView.setWebChromeClient(new WebChromeClient(){
            public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePathCallback,WebChromeClient.FileChooserParams fileChooserParams){
                if(uploadMessage != null){
                    uploadMessage.onReceiveValue(null);
                }
                uploadMessage = filePathCallback;
                Intent intent;
                intent = fileChooserParams.createIntent();
                try{
                    startActivityForResult(intent,REQUEST_SELECTED_FILE);
                } catch (ActivityNotFoundException e){
                    uploadMessage = null;
                    return false;
                }
                return true;
            }
        });
    }
}
https://xn--90acbu5aj5f.xn--p1ai/?p=5129
Categories: Android Tags:
  1. Пока что нет комментариев.
Похожие публикации