2

私は問題があります.. :(

拡張 WebViewClient のように自分で実装したカスタム webView があります。アプリケーションの 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 に答える