Android Tutorial for GeckoView: Getting Started | raywenderlich.com

Hi Arturo

I have already considered this. onLoadRequest in NavigationDelegate gives me just the option to stop the loading.

But I need to return a WebResponse. Looks like I can’t do it from onLoadRequest.
Scenario is to stop a load of an URL and return a (custom) WebResponse into GeckoView that might load a different page.

Any ideas for that?

Thanks
Jochen

Hi @scubainstructor,

The code above could be updated to handle this scenario :slight_smile:
just by using the session object to load the new URL.

  private fun createNavigationDelegate(): GeckoSession.NavigationDelegate {
    return object : GeckoSession.NavigationDelegate {

      override fun onLoadRequest(session: GeckoSession, request: GeckoSession.NavigationDelegate.LoadRequest): GeckoResult<AllowOrDeny>? {
        // Conditioning when the request should load.
        return if (request.uri.contains("pattern")) {
          GeckoResult.ALLOW
        } else {
          // Here is the trick :) 
          // load a new URL
          geckoSession.loadUri("newURL")
         // Cancels the actual load
          GeckoResult.DENY
        }
      }
    }
  }

You may be interested in taking a look at Mozilla Android Components. We have encapsulated this behavior in a RequestInterceptor, here is how is implemented and here you can see an example.

Hope it helps :slight_smile:

I have switched to GeckoView my Android application. Solves an issue I was facing playing Youtube videos on normal WebView. My concern is this: my APK file size raised from 2.5 MB to 162 MB after I have switched to GeckoView. Is this normal? How to keep the file size smaller?

Hi acrolink, I believe the size is that big because you are using a debug build, if you try with a release build the APK size must decrease significantly, if not please open an issue in the GeckoView Repo because this shouldn’t be normal.

1 Like

I was able to decrease the size down to 46 MB by adding:

 ndk {
                abiFilters "armeabi-v7a"
            }

like this (build.gradle):

   buildTypes {
        release {
            ndk {
                abiFilters "armeabi-v7a"
            }
            debuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        
    }
1 Like

I am trying to download the file from the awesomeBrowser. It’s failed to download the file. Can you add the how to handle the download and how can I see the request headers on any request?

@dhksrini The reason for that is that GeckoView does not provide a default implementation for that. You need to override GeckoSession.ContentDelegate (and in this case onExternalResponse() ).

See API docs: GeckoSession.ContentDelegate (geckoview 108.0.20221020215126 API)

You can take the implementation is used by the “GeckoView Example app” and you can find that code here: GeckoViewActivity.java - mozsearch

@amejia481 I asked this question on github but I didn’t get an answer :disappointed: :disappointed:
please please answer my question :sweat:

https://github.com/mozilla-mobile/android-components/issues/5968

I want to use GeckoView’s loadUri() or GeckoEngineView’s loadData() or loadUrl() to load local html files from asset folder in android.

sorry for my bad english.

Even for release build the size is big. Analyzing the APK shows that the major file contributing to the large size, for instance, when targeting armeabi-v7a is libxul.so (58.9 MB) in lib folder.

The question was answered in the GitHub issue :slight_smile:

1 Like

Hello,

Is there any way to use the GeckoView on IOS?

Thanks

1 Like

Unfortunately iOS doesn’t allow to run any web engine apart from WebKit.

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!