Answer the question
In order to leave comments, you need to log in
How to implement opening links inside webview?
Hello.
The site has a mobile application - a bare webview. The problem is that when you click on the link mysite.ru/any/link in the application, the main page opens, and not the destination url. Can you please tell me how to fix this?
And sorry in advance for a possibly stupid question, I'm not a developer at all.
Done: Added to the
manifest
in the mainactivity
Uri data = getIntent().getData();
Answer the question
In order to leave comments, you need to log in
Something like this
public class MainActivity extends AppCompatActivity {
WebView webView;
private Activity activity;
private SwipeRefreshLayout swipe;
public MainActivity()
{
activity = this;
}
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
// Включаем js
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
// все ссылки, в которых содержится домен
// будут открываться внутри приложения
if (url.contains("my-site.ru")) {
return false;
}
// все остальные ссылки будут спрашивать какой браузер открывать
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
activity.startActivity(intent);
return true;
}
});
String urlAddress = getString(R.string.main_url_schema) + "://" + getString(R.string.main_url_domain);
webView.loadUrl(urlAddress);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question