【发布时间】:2014-08-11 15:27:08
【问题描述】:
对不起我的英语.. 我有一个 web 项目,我将在应用程序中使用 android,但在应用程序的一部分必须使用 input type="file",但它在 Android Webview 中不起作用,当尝试单击“选择文件”它只是静态的并且不会打开打开,但是使用浏览器 url 它可以完美运行。已经尝试了几种方法来解决这个问题,但没有成功。 任何人都知道我该如何修复.. 请让我知道...
public class MainActivity extends Activity {
private String URL = "http://localhost:8080/myproject/upload.html";
private WebView webView;
private ValueCallback<Uri> uploadMessage;
private final static int FILECHOOSER_RESULTCODE = 1;
private static String registrationId = "";
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == FILECHOOSER_RESULTCODE) {
if (uploadMessage == null) return;
Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
uploadMessage.onReceiveValue(result);
uploadMessage = null;
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.container);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient()
{
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
Log.i("openFileChooser", " IN ");
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
startActivityForResult(Intent.createChooser(i,"File Chooser"), 222);
}
@SuppressWarnings("unused")
public void openFileChooser( ValueCallback uploadMsg, String acceptType ) {
// Intent i = new Intent(Intent.ACTION_GET_CONTENT);
Log.i("openFileChooser", " IN ");
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i, "File Browser"), 222);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
// openFileChooser(uploadMsg);
Log.i("openFileChooser", " IN ");
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
startActivityForResult( Intent.createChooser( i, "File Chooser" ), 2223 );
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(URL);
}
【问题讨论】: