簡體   English   中英

來自android webview的FilePicker只工作一次

[英]FilePicker from android webview working only once

我需要從webview中選擇一個圖像並將其上傳到服務器上。 代碼有效,但如果我沒有選擇任何東西就按下,下次控件不會進入onShowFileChooser

我已經在Android瀏覽器上檢查了相同的內容並且它在那里工作,所以必須有一些我缺少的東西。

以下是代碼:

web.setWebChromeClient(new BizzerClient());
        web.setWebViewClient(new WebViewClient(){

            //=========================================
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url){
                if(url.contains(Domain) && !url.startsWith(SMS)){
                    //== if url is of same site and not related to sms, do nothing                  
                }else{
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(url));
                    startActivity(i);
                    return true;
                }               
                return false;
            }
        });

//=========================================
    @Override  
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {  
        if(requestCode==FileChooser){  
            Uri result = intent == null || resultCode != RESULT_OK ?null:Uri.parse(intent.getDataString());
            if(result==null) return;
            if(fPathCallback!=null){
                fPathCallback.onReceiveValue(new Uri[]{result});
                fPathCallback = null;
            }else{
                upload.onReceiveValue(result);  
                upload = null;
            }
        }
    }  


    //=====================================================
    class BizzerClient extends WebChromeClient{

        //=========================================
        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            upload = uploadMsg;         
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
            i.addCategory(Intent.CATEGORY_OPENABLE);  
            i.setType("image/*");  
            startActivityForResult(Intent.createChooser(i,"File Chooser"), FileChooser); 
        }

        //=========================================
        //== For Android 3.0+
        public void openFileChooser( ValueCallback uploadMsg, String acceptType ) {
            upload = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("*/*");
            startActivityForResult(Intent.createChooser(i, "File Browser"),FileChooser);
        }

        //=========================================
        //== For Android 4.1
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
            upload = uploadMsg; 
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
            i.addCategory(Intent.CATEGORY_OPENABLE);  
            i.setType("image/*");  
            startActivityForResult( Intent.createChooser( i, "File Chooser" ), FileChooser );
        }

        //=========================================
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,WebChromeClient.FileChooserParams fileChooserParams) {
            fPathCallback = filePathCallback;   
            Toast.makeText(getApplicationContext(), "A", Toast.LENGTH_SHORT).show();
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
            i.addCategory(Intent.CATEGORY_OPENABLE);  
            i.setType("image/*");  
            startActivityForResult(Intent.createChooser(i,"File Chooser"), FileChooser); 
            return true;
        }
    }

有誰知道如何解決這一問題?

我的同事有完全相同的問題,他已經修好了

upload.onReceiveValue(空)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM