Android-оболочка не загружает файл
У меня есть приложение для Android, которое просто обертка вокруг моего мобильного сайта. У меня есть одно веб-представление, которое просто указывает на URL-адрес для входа на мой сайт. Когда я захожу на свой мобильный сайт в обычном браузере, я могу скачать PDF-файлы, когда нажимаю на кнопку (через href="url, который возвращает pdf"). Однако на моей обертке я не могу ее скачать. Я предполагаю, что это как-то связано с моими сетевыми настройками или каким-либо методом, который мне нужно переопределить. Как я могу заставить свою обертку загружать файл как обычный браузер?
код:
public class MainActivity extends Activity {
private static final String TAG = "TAG";
private WebView myWebViewGlobal=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove title bar as we already have it in the web app
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Point to the content view defined in XML
setContentView(R.layout.main);
//Configure the webview setup in the xml layout
WebView myWebView=(WebView) findViewById(R.id.webview);
myWebViewGlobal=myWebView;
WebSettings webSettings = myWebView.getSettings();
//Yes, we want javascript, pls.
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccess(true);
myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.setDownloadListener(new DownloadListener()
{
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.ECLAIR) {
try {
Log.d(TAG, "Enabling HTML5-Features");
Method m1 = WebSettings.class.getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
m1.invoke(webSettings, Boolean.TRUE);
Method m2 = WebSettings.class.getMethod("setDatabaseEnabled", new Class[]{Boolean.TYPE});
m2.invoke(webSettings, Boolean.TRUE);
Method m3 = WebSettings.class.getMethod("setDatabasePath", new Class[]{String.class});
m3.invoke(webSettings, "/data/data/" + getPackageName() + "/databases/");
Method m4 = WebSettings.class.getMethod("setAppCacheMaxSize", new Class[]{Long.TYPE});
m4.invoke(webSettings, 1024*1024*8);
Method m5 = WebSettings.class.getMethod("setAppCachePath", new Class[]{String.class});
m5.invoke(webSettings, "/data/data/" + getPackageName() + "/cache/");
Method m6 = WebSettings.class.getMethod("setAppCacheEnabled", new Class[]{Boolean.TYPE});
m6.invoke(webSettings, Boolean.TRUE);
Method m7 = WebSettings.class.getMethod("setAllowContentAccess", new Class[]{Boolean.TYPE});
m7.invoke(webSettings, Boolean.TRUE);
Method m8 = WebSettings.class.getMethod("setAllowFileAccessFromFileURLs", new Class[]{Boolean.TYPE});
m8.invoke(webSettings, Boolean.TRUE);
Method m9 = WebSettings.class.getMethod("setAllowUniversalAccessFromFileURLs", new Class[]{Boolean.TYPE});
m9.invoke(webSettings, Boolean.TRUE);
Method m10 = WebSettings.class.getMethod("setLoadsImagesAutomatically", new Class[]{Boolean.TYPE});
m10.invoke(webSettings, Boolean.TRUE);
Method m11 = WebSettings.class.getMethod("setLoadsImagesAutomatically", new Class[]{Boolean.TYPE});
m11.invoke(webSettings, Boolean.TRUE);
Log.d(TAG, "Enabled HTML5-Features");
}
catch (NoSuchMethodException e) {
Log.e(TAG, "Reflection fail", e);
}
catch (InvocationTargetException e) {
Log.e(TAG, "Reflection fail", e);
}
catch (IllegalAccessException e) {
Log.e(TAG, "Reflection fail", e);
}
}
//Make sure links in the webview is handled by the webview and not sent to a full browser
myWebView.setWebViewClient(new WebViewClient());
//And let the fun begin
myWebView.loadUrl("http://mywebsite.com/login.php");
}
@Override
public void onBackPressed()
{
if(myWebViewGlobal.canGoBack())
{
myWebViewGlobal.goBack();
}
return;
}
}