在Android 4.4(KitKat)中访问新图库之前,我使用此方法在SD卡上获得了真正的路径:
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
startManagingCursor(cursor);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
Run Code Online (Sandbox Code Playgroud)
现在,Intent.ACTION_GET_CONTENT返回不同的数据:
之前:
content://media/external/images/media/62
Run Code Online (Sandbox Code Playgroud)
现在:
content://com.android.providers.media.documents/document/image:62
Run Code Online (Sandbox Code Playgroud)
我怎么能设法获得SD卡上的真实路径?
我<input type="file">
在android webview上使用了它.我得到了它的工作感谢这个线程:
WebView中的文件上传
但接受的答案(或任何其他)不再适用于android 4.4 kitkat webview.
有谁知道如何解决它?
它也不适用于目标18.
我看了一些android 4.4源代码,似乎WebChromeClient没有改变,但我认为setWebChromeClient
不再适用于kitkat webview,或者至少不是这个openFileChooser
功能.
我正在开发一款Android应用.基本上它是一个WebView
和一个progressBar.Facebook的移动网站(m.facebook.com)被加载到WebView
.
当我单击"选择文件"按钮上传图像时,没有任何反应.我已经尝试了所有解决方案,但没有一个能够正常工作.我正在测试运行4.0.3的Galaxy Note(GT-N7000).我的最低SDK版本是版本8.
这是我的代码了解更多信息......
public class IStyla 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;
}
}
private class MyWebChromeClient extends WebChromeClient {
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Intent i …
Run Code Online (Sandbox Code Playgroud) 我们正在创建一个使用webview的应用程序,并将访问用户需要上传文件的页面.我们遇到Android 4.4问题,文件选择器无法打开,单击上传按钮不会发生任何事情.此功能适用于使用openFileChooser方法的早期版本,如下所示:
webview.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<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
}
// For Android 3.0+
public void openFileChooser(ValueCallback uploadMsg, String acceptType) {
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 4.1
public void openFileChooser(ValueCallback<Uri> uploadMsg, …
Run Code Online (Sandbox Code Playgroud) 此应用程序中的WebView打开一个带有上传按钮的页面.
下面是允许打开对话框以从库或相机上传图像的代码块.
在我的活动中我有:
private WebView wv;
//make HTML upload button work in Webview
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;
}
}
Run Code Online (Sandbox Code Playgroud)
在onCreate中我有以下内容:
wv.setWebChromeClient(new WebChromeClient() {
private Uri imageUri;
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType ) {
File imageStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyApp");
// …
Run Code Online (Sandbox Code Playgroud) android android-intent android-image android-webview android-camera
目标:能够将任何类型的文件附加到<input type="file" />
in webview
中Android 4.1+
.(Android 5+很好)
我openFileChooser
根据我发现的几个例子设置了我认为合适的东西.它的工作原理上4.1
而不是在4.4.4
哪里连接没有自己的文件名的文件正确设置.
相反,将文件名设置为intent.mData
返回的最后一个路径onActivityResult
,.eg,对于mData
值content://com.android.providers.downloads.documents/document/2
,文件名将是2
-without extension of course-而名称应为image.png
.
我该怎么办才能修复它?我的代码会有问题吗?
我在模拟器上进行测试:Galaxy Nexus,API 19,目标:默认
请参阅下面的代码.
webView.setWebChromeClient(new WebChromeClient() {
public void openFileChooser(ValueCallback<Uri> valueCallback, String acceptType, String capture) {
if (UseWebViewActivity.this.valueCallback != null) {
UseWebViewActivity.this.valueCallback.onReceiveValue(null);
}
UseWebViewActivity.this.valueCallback = valueCallback;
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
contentSelectionIntent.setType("*/*");
startActivityForResult(Intent.createChooser(contentSelectionIntent,
getString(R.string.file_chooser_title)), INPUT_FILE_REQUEST_CODE);
}
});
// ...
protected void onActivityResult(int …
Run Code Online (Sandbox Code Playgroud) 这是我的html浏览代码.
这是我的android代码,它为浏览文件加载html文件并在服务器上传.
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(AndroidConstants.MAIN_URL());
toast(AndroidConstants.MAIN_URL());
webView.loadUrl(AndroidConstants.MAIN_URL());
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
// TODO Auto-generated method stub
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
WebViewActivity.this.startActivityForResult(Intent.createChooser(i,"Image Chooser"), 2533);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
openFileChooser(uploadMsg);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String …
Run Code Online (Sandbox Code Playgroud) 我应该在应用程序的webview中显示一个网页.该页面包含一个html表单,其中一个字段是文件.所以它就像......
<input type="file" name="file">
Run Code Online (Sandbox Code Playgroud)
如果我在浏览器中打开页面并按下选择文件按钮,弹出文件选择器,一切都很好,但是当我按下webview中的选择文件按钮时,没有任何反应:/
任何想法如何使这项工作?
我有一个加载WebView的应用程序.在WebView内部,加载的页面具有文件上载控件(html input = file).按钮是可见的,它显示"选择文件",但是如果单击该按钮则没有任何反应.如果您使用默认的Android浏览器并加载同一页面并单击按钮,它会弹出一个窗口,让您从图库,文件等中选择一个文件.为什么它不能从WebView中运行?
我想我需要覆盖一些东西,但我不知道那可能是什么.基本上我希望能够从我的应用程序内部上传照片,就像我已经可以从浏览器中运行的Web应用程序一样.本机app/webview版本应该相同,但单击"选择文件"按钮不会执行任何操作.
谢谢.