这是我显示当前网页网址的代码。该代码工作正常,但我只想从 url 获取特定值。
我关注这篇文章,但对我没有帮助。代码在运行时爆炸。浏览Playstore时我只想要ID
public class WebViewClientDemoActivity extends Activity {
/** Called when the activity is first created. */
WebView web;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
web = (WebView) findViewById(R.id.webview01);
web.setWebViewClient(new myWebClient());
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("https://play.google.com/store/apps");
}
public class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
String[] splited = url.split("&");
String[] id = splited[0].split("?id=");
Toast.makeText (getApplicationContext(), id.toString(),
Toast.LENGTH_SHORT).show ();
view.loadUrl(url);
return true;
// this is example url i just want to get only id from which url
//https://play.google.com/store/apps/details?id=com.eamobile.monopoly_row_wf&feature
//=more_from_developer#?t=W251bGwsMSwyLDEwMiwiY29tLmVhbW9iaWxlLm1vbm9wb2x5X3Jvd193ZiJd
}
}
// To handle "Back" key press event for WebView to go back to previous screen.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
web.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}