关于在Android上使openfilechooser工作的问题有几个问题,我已经应用了推荐的解决方案。
我的问题不在于它还没有开始工作4.4但是接下来我将解决这个问题,但我只需要它在我的测试设备4.2.2(注8)上工作,但是一旦选择了图像它就会返回一个空白的白色屏幕。
我已经重新检查了我的代码并审查了许多解决方案,他们都提供了相同的解决方案,但我似乎无法找到错误。
继承我的代码:
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;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_team_page);
mHandler = new Handler();
getUser = ((MyData)getApplicationContext());
TimeZone tz = TimeZone.getDefault();
Date now = new Date();
int offsetFromUtc = tz.getOffset(now.getTime()) / 3600000;
m2tTimeZoneIs = Integer.toString(offsetFromUtc);
userCredentials = getApplicationContext().getSharedPreferences("me2team", MODE_PRIVATE);
isShowingDesktop = false;
m2tUser = getUser.getCredentialsUser();
m2tPswd = getUser.getCredentialsPwd();
isPremiumUser = getUser.getPremiumUser();
tempWebURL = getResources().getString(R.string.teamURLMobile);
webURL = tempWebURL + "?username=" + m2tUser + "&password=" + m2tPswd + "&mobile=1&offSetHours=" + m2tTimeZoneIs;
webView = (WebView) findViewById(R.id.teamWebView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSavePassword(false);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(false); //as per Janet's request
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.getSettings().setLoadWithOverviewMode(true);
webView.setInitialScale(70);
WebSettings settings = webView.getSettings();
settings.setDomStorageEnabled(true);
webView.setAlpha(255);
webView.setWebChromeClient(new WebChromeClient() {
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
TeamPage.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);
}
// For Android 3.0+
@SuppressWarnings("unused")
public void openFileChooser( ValueCallback uploadMsg, String acceptType ) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
TeamPage.this.startActivityForResult(
Intent.createChooser(i, "File Browser"),
FILECHOOSER_RESULTCODE);
}
//For Android 4.1
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
TeamPage.this.startActivityForResult( Intent.createChooser( i, "File Chooser" ), TeamPage.FILECHOOSER_RESULTCODE );
}
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
{
activity.setTitle(R.string.app_name);
}
}
});
webView.setWebViewClient(new WebViewClient());
我检查了服务器chap,当我选择文件时他没有看到任何错误,所以就像它停止做任何事情一样。事情是,如果我退出网站,然后重新登录,我仍然得到相同的白色屏幕?直到我重新启动它返回到网页的应用程序(记住登录详细信息并自动登录)。
和想法?