2 xiaoyan 12 xiaoyan_12 于 2013.09.12 16:53 提问

在shouldOverrideUrlLoading中加载intent

我想在 shouldOverrideUrlLoading 中加载一个 intent。
VariablesStorage.class

public class VariablesStorage
{
private static VariablesStorage instance;
public static  Context webViewContext;
public  WebView webView;

        public static void initInstance()
    {
        if (instance == null)
        {
            // Create the instance
            instance = new VariablesStorage();
        }
    }
    public static VariablesStorage getInstance()
    {
        // Return the instance
        return instance;
    }
    private VariablesStorage()
    {
    }
public void loadWebView() {
        webView.getSettings().setJavaScriptEnabled(true);
 if (isOnline())
        {
            webView.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {

                    if (url.startsWith("inapp://")) {
                         Intent intent = new Intent(this,profilepictureview.class);
                         intent.putExtra("img",Uri.parse(url).getHost().toString());
                         startActivity(intent);

                        }else
                        {
                            view.getContext().startActivity(
                             new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                        }                       
                    return true;
                }
                @Override
                public void onReceivedError( WebView view, int errorCode, String description, String failingUrl) 
                    {
                    }
                @Override
                public void onPageFinished(WebView view, String url) {
                    if(mProgress.isShowing()) {
                        mProgress.dismiss();
                    }
                }
            });
            webView.loadUrl(Url);
        }else
        {
            webView.loadData(customHtml, "text/html;charset=utf-8", "UTF-8");
        }
    }
}

然后在 webview activity 中调用 VariablesStorage.getInstance().loadWebView();
WebViewActivity.class

public class WebViewActivity extends Activity {

    SharedPreferences pref;
    TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webviewtab);
 VariablesStorage.getInstance().webViewContext = this;
        VariablesStorage.getInstance().webView = (WebView) findViewById(R.id.webView);
            VariablesStorage.getInstance().loadWebView();
}

当我在 shouldOverrideUrlLoading 里面添加代码时:

Intent intent = new Intent(this,profilepictureview.class);
 intent.putExtra("img",Uri.parse(url).getHost().toString());
 startActivity(intent);

出现错误:

The constructor Intent(new WebViewClient(){}, Class<profilepictureview>) is undefined

如何实现这个功能呢?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!