0

I have a webview which has this class as webviewclient. This is to make links to pages open in the webview, and links to downloadable files open with the default browser. Here it is:

class LinkWebView extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url.contains("/WS/") | url.contains("/Francesco/")
            | url.contains("/Gabriele/")) {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            ClubCiprianisActivity cca = new ClubCiprianisActivity();
            cca.comincia(intent);
        } catch (Exception ex) {
            ClubCiprianisActivity cca = new ClubCiprianisActivity();
            cca.tostizza(ex.getMessage());
        }
    } else {
        view.loadUrl(url);
    }
    return true;
}

}

this webview will load only urls from a specific website so the conditional to choose wheter to open the link in the webview or in the default browser is correct for that website.

ClubCiprianisActivity is the only activity shown in my application, with the webview and all the rest.

method comincia of ClubCiprianisActivity is this:

public void comincia(Intent intent) {
    startActivity(intent);
}

I had to make it because Eclipse doesn't recognize the method startActivity in the webviewclient class. tostizza is just showing a Toast because I can't do that either in the webviewclient class. My problem is that when I open al link to a webpage it opens normally, but when I try to open a downloadable link, going into the shouldoverride... I get an error.

4

3 回答 3

2

您永远不应该手动启动您的活动。而是在 LinkWebView 类中创建一个构造函数并将上下文作为参数发送到此构造函数,然后调用 context.startActivity(Intent)

于 2012-04-13T20:44:24.130 回答
1
package com.example.maintosecond;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;

我有同样的问题,如果你导入 content.Intent 类,你应该很高兴。

于 2013-07-28T02:32:27.750 回答
1
context.startActivity(intent);

或者

  YourActivityname.this.startActivity(intent);
于 2012-04-13T20:44:32.753 回答