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.

asked Apr 13, 2012 at 20:39

3 Answers 3

2

You should never initiate your activity manually..instead make a constructor in the LinkWebView class and send the context as parameter to this constructor then call context.startActivity(Intent)

answered Apr 13, 2012 at 20:44
Sign up to request clarification or add additional context in comments.

1 Comment

Ehm... Could you also tell me how to do this? I think I just didn't get it.
1
context.startActivity(intent);

or

 YourActivityname.this.startActivity(intent);
answered Apr 13, 2012 at 20:44

3 Comments

It actually doesn't work... Eclipse says "No enclosing instance of the type ClubCiprianisActivity is accessible in scope".
what have you tried before ask me about above comment ....put line on google search box....Make some efforts ....
I kinda solved the problem, unless, with Eclipse. When I'll have the updating of the sdk's finished I'll try it.
1
package com.example.maintosecond;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;

I had the same problem, if you import the content.Intent class you should good to go.

answered Jul 28, 2013 at 2:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.