Skip to content

Instantly share code, notes, and snippets.

@Kudo
Created February 17, 2024 05:38
Show Gist options
  • Save Kudo/8c6becbb553c7b2c9baeb4b9b0e7616e to your computer and use it in GitHub Desktop.
Save Kudo/8c6becbb553c7b2c9baeb4b9b0e7616e to your computer and use it in GitHub Desktop.
Customize User-Agent for Expo
diff --git a/android/app/src/main/java/dev/expo/kudo/sdk50/MainApplication.kt b/android/app/src/main/java/dev/expo/kudo/sdk50/MainApplication.kt
index e9a2f7a..fbf9aae 100644
--- a/android/app/src/main/java/dev/expo/kudo/sdk50/MainApplication.kt
+++ b/android/app/src/main/java/dev/expo/kudo/sdk50/MainApplication.kt
@@ -14,10 +14,12 @@ import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.flipper.ReactNativeFlipper
+import com.facebook.react.modules.network.OkHttpClientProvider
import com.facebook.soloader.SoLoader
import expo.modules.ApplicationLifecycleDispatcher
import expo.modules.ReactNativeHostWrapper
+import okhttp3.Interceptor
class MainApplication : Application(), ReactApplication {
@@ -55,6 +57,14 @@ class MainApplication : Application(), ReactApplication {
if (BuildConfig.DEBUG) {
ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager)
}
+ OkHttpClientProvider.setOkHttpClientFactory {
+ OkHttpClientProvider.createClientBuilder()
+ .addInterceptor(Interceptor { chain ->
+ val request = chain.request().newBuilder().header("User-Agent", "My-UA").build()
+ chain.proceed(request)
+ })
+ .build()
+ }
ApplicationLifecycleDispatcher.onApplicationCreate(this)
}
@Kudo
Copy link
Author

Kudo commented Feb 17, 2024

cng-patches/android+e595dc4a98abafdbbb9eb9979064bb34.patch that is manually changed and generated by bunx patch-project -p android

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment