我的工作,它使用Web视图在它的活动之一的应用程序。我重视与web内容的Java脚本接口。我需要调用基于click事件捆绑数据的活动(可以说,触摸事件)。我可以将数据传递回Java脚本接口,但它没有让我叫startActivity(意向)。有没有其他办法,我可以调用一个活动。在此先感谢!
I am working on an application which uses web view in one of it's activities. I have attached a java script interface with the web content. I need to call an activity with data in bundle based on the click event(can say touch event). I can pass data back to Java script interface but it's not letting me call startActivity(Intent). Is there any other way I can call an activity. Thanks in advance!!
您可以使用web视图的OnClick检查哪个链接被点击,并采取相应的行动。像这样的:
You can use the WebView OnClick to check which link was clicked and take action accordingly. Like this:
wv.setOnClickListener(new OnClickListener() {
public boolean onClick(View v){
HitTestResult result = wv.getHitTestResult();
String url = result.getExtra();
//Log.i(myTag, url);
if(url.equals("which-ever-url-you-want-to-override.com"){
Intent i = new Intent(getApplicationContext(), yourActivity.class);
startActivity(i);
}
}
});
getHitTestResult()会给你一个对象,它会告诉你在哪里链接指向的URL。您可以使用它来使不同的链接你的应用程序中做不同的事情。
getHitTestResult() will give you an object that will tell you where the URL of the link points. You can use this to make different links do different things within your app.