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
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() 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.
Here are the things that you need to do to support this :
For the activity to be launched : Handle the android.intent.category.BROWSABLE category with the a particular scheme.
In WebView onClick, load the url starting with scheme handled by the app.
For ex : TestActivity
<manifest>
<application>
<activity>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="test-app"/>
</intent-filter>
</activity>
</application>
</manifest>
URL to load after web view click :
webView.loadUrl( "test-app://data-that-you-want-to-transfer" );
HTH !