问题描述
是如何DownloadListener这样运作?也许我错过了一些东西。我做了以下内容:
How is the DownloadListener supposed to work? Probably I miss something. I did the following:
- 注册在一个网页视图DownloadListener。
- 打开一个HTML页的WebView,包含链接(的作品)。
- 如果我点击链接,DownloadListener不叫。
下面是code的一小部分。
Here is a short portion of the code.
package rene.android.learnit;
import android.app.*;
import android.os.Bundle;
import android.webkit.*;
public class ShowWeb extends Activity
implements DownloadListener
{
public static Lesson L;
WebView WV;
@Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.showweb);
WV=(WebView)findViewById(R.id.showweb);
WV.setDownloadListener(this);
WV.loadUrl("http://android.rene-grothmann.de/courses.html");
}
public void onDownloadStart (String url, String agent, String disposition,
String mimetype, long size)
{
Main.log(url+" "+mimetype+" "+size);
}
}
日志记录工作(我使用这个到处检查我的程序),但没有被记录,因此回调不叫。什么情况是:视图尝试下载该文件,并失败,因为zip文件不支持我的Android
The logging works (I am using this everywhere to check my program), but nothing is logged, so the callback is not called. What happens is: The view tries to download the file, and fails, since zip files are not supported on my Android.
链接进入到一个压缩文件。它是通常的
The link goes to a zip-file. It is a usual
<a href=...>...</a>
链接。
我试图找出报考zip文件的意图的替代方法。但文档是如此稀少,我不能这样做。如果我有,有一个例子吗?
I tried to figure out the alternative method of registering an intent for zip files. But the documentation is so sparse, I could not do that. If I have to, is there an example?
任何想法?
谢谢你,R。
推荐答案
看来DownloadListener确实不能正常工作。然而,我们可以使用下面的技巧:
It seems the DownloadListener is indeed not working. However, one can use the following trick:
package rene.android.learnit;
import android.app.*;
import android.os.Bundle;
import android.webkit.*;
public class ShowWeb extends Activity
{
public static Lesson L;
WebView WV;
@Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.showweb);
WV=(WebView)findViewById(R.id.showweb);
WV.setWebViewClient(new WebViewClient()
{
public void onLoadResource (WebView view, String url)
{
Main.log(url);
if (url.endsWith(".zip"))
{
finish();
}
else super.onLoadResource(view,url);
}
}
);
WV.loadUrl("http://android.rene-grothmann.de/courses.html");
}
}
这将允许处理所有zip文件。
This will allow to handle all zip files.
这篇关于downloadlistener不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!