我在stackoverflow上找到了答案,但丢失了链接,所以这就是我必须做的......
在我的 MainActivity 课程中,我这样做......
...
import android.webkit.ValueCallback;
import android.net.Uri;
public class MainActivity extends Activity {
...
private ValueCallback<Uri> mUploadMessage;
private final static int FILECHOOSER_RESULTCODE=1;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if(requestCode==FILECHOOSER_RESULTCODE) {
if (null == mUploadMessage) return;
Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
mUploadMessage.onReceiveValue(result);
mUploadMessage = null;
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new MyWebViewClient());
webView.setWebChromeClient(
new WebChromeClient() {
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Log.d ("myfirstapp_tag", "1) MainActivity.java loaded openFileChooser" );
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
Log.d ("myfirstapp_tag", "2) MainActivity.java loaded openFileChooser" );
i.addCategory(Intent.CATEGORY_OPENABLE);
Log.d ("myfirstapp_tag", "3) MainActivity.java loaded openFileChooser" );
i.setType("image/*");
Log.d ("myfirstapp_tag", "4) MainActivity.java loaded openFileChooser" );
MainActivity.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);
Log.d ("myfirstapp_tag", "5) MainActivity.java loaded openFileChooser" );
}
}
);
webView.loadUrl("http://example.com/EZC.php");
setContentView(webView);
Log.d ("myfirstapp_tag", "MainActivity.java loaded URL and set Content View." );
}
}