I am trying to make my android web browser open only specific urls. Because of that, I want to check if loaded url meets the requirements, and according to that to do something. I saw many answers about WebView, but since I have to use open source browser (Mozilla Firefox) I am using gecko. Here is my code, I tried to do something with onLoadRequest but I do not know how to make it work. Thanks.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GeckoView view = findViewById(R.id.geckoView);
GeckoSession session = new GeckoSession();
GeckoRuntime runtime = GeckoRuntime.create(this);
session.open(runtime);
view.setSession(session);
session.loadUri("https://www.google.com");
GeckoSession.NavigationDelegate.LoadRequest loadRequest=new GeckoSession.NavigationDelegate.LoadRequest();
session.getNavigationDelegate().onLoadRequest(session,loadRequest);
}
@Override
public void onLoadRequest(GeckoSession session, GeckoSession.NavigationDelegate.LoadRequest request)
{
if(request.uri.contains("mail"))
GeckoResult.fromValue(AllowOrDeny.ALLOW);
else
GeckoResult.fromValue(AllowOrDeny.DENY);
}