2

我有个问题.. :(

我自己实现了一个自定义 webView,就像扩展 WebViewClient 一样。在应用程序的 html 端,我有一个标签<input type='file' id='media' name='media' accept="image/*" capture="camera" />,但我无法让它工作!

我遵循了很多教程,但他们都使用WebChromeclient;就我而言,由于应用程序的复杂性,我使用WebViewClient.

有解决办法吗?请..

这是我的课

public class MyWebView extends WebViewClient{
private static Context context;
private static HttpClient client;
private static SharedPreferences prefs;

public MyWebView(Context context, HttpClient client, SharedPreferences prefs){
    super();    
    MyWebView.context = context;
    MyWebView.client = client;
    MyWebView.prefs = prefs;
}


@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {                                     
    //some operation with cookie
}
4

1 回答 1

0

我对 webview 有同样的问题。假设你html看起来像

<html>

<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file">
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>

这是解决我问题的全部内容

package com.example.webviewtest;

public class MainActivity extends Activity {

private WebView wv;

private ValueCallback<Uri> mUploadMessage;
private final static int FILECHOOSER_RESULTCODE = 1;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    wv = new WebView(this);
    wv.setWebViewClient(new WebViewClient());


    wv.setWebChromeClient(new WebChromeClient() {


        // The undocumented magic method override
        // Eclipse will swear at you if you try to put @Override here


        // For Android < 3.0
        public void openFileChooser(ValueCallback uploadMsg) {

            Log.i("For Android < 3.0", "called");

            mUploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);


            i.addCategory(Intent.CATEGORY_OPENABLE);

            i.setType("*/*");
            MainActivity.this.startActivityForResult(
                    Intent.createChooser(i, "File Browser"),
                    FILECHOOSER_RESULTCODE);
        }

        // For Android 3.0+
        public void openFileChooser(ValueCallback uploadMsg,
                String acceptType) {

            Log.i("For Android 3.0+", "called");

            mUploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);

            i.addCategory(Intent.CATEGORY_OPENABLE);

            i.setType("*/*");
            MainActivity.this.startActivityForResult(
                    Intent.createChooser(i, "File Browser"),
                    FILECHOOSER_RESULTCODE);
        }

         public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
             openFileChooser(uploadMsg);

             Log.i("For Android Jellybeans", "called");

            mUploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);

            i.addCategory(Intent.CATEGORY_OPENABLE);

            i.setType("*/*");
            MainActivity.this.startActivityForResult(
                    Intent.createChooser(i, "File Browser"),
                    FILECHOOSER_RESULTCODE);

         } 

    });

    setContentView(wv);
    wv.loadUrl("http://blue.genetechz.com/qadir/");
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
        Intent intent) {

    Log.i("onActivityResult", "called");

    if (requestCode == FILECHOOSER_RESULTCODE) {
        if (null == mUploadMessage){

            Log.i("if", "return called");
            return;
        }else{

            Uri result = intent == null || resultCode != RESULT_OK ? null
                    : intent.getData();
            mUploadMessage.onReceiveValue(result);
            mUploadMessage = null;
            Log.i("else", "inner Called");

        }

    } else {

        Log.i("Else", "Called");

        // super.onActivityResult(requestCode, resultCode, intent);
        // IPlugin callback = this.activityResultCallback;
        // if (callback != null) {
        // callback.onActivityResult(requestCode, resultCode, intent);
        // }
    }
}

@Override
public void onBackPressed() {
    if (wv.canGoBack() == true) {
        wv.goBack();
    } else {
        MainActivity.this.finish();
    }
}

}
于 2013-11-11T05:02:12.553 回答