Skip to content

Instantly share code, notes, and snippets.

@samjarman
Created September 15, 2016 21:42
Show Gist options
  • Save samjarman/9140e9b5f5e69e0e62c93ff1f34af614 to your computer and use it in GitHub Desktop.
Save samjarman/9140e9b5f5e69e0e62c93ff1f34af614 to your computer and use it in GitHub Desktop.
This lets you set a custom user agent.
package com.carnivalmobile.webviewhack;
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.webkit.WebView;
import com.carnival.sdk.MessageActivity;
public class UserAgentHack implements Application.ActivityLifecycleCallbacks {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
}
@Override
public void onActivityStarted(Activity activity) {
}
@Override
public void onActivityResumed(Activity activity) {
if (activity instanceof MessageActivity) {
WebView webView = (WebView) activity.findViewById(R.id.webView);
if (webView != null) {
webView.getSettings().setUserAgentString("Custom User Agent");
}
}
}
@Override
public void onActivityPaused(Activity activity) {
}
@Override
public void onActivityStopped(Activity activity) {
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
}
@Override
public void onActivityDestroyed(Activity activity) {
}
}
// Call like this
registerActivityLifecycleCallbacks(new UserAgentHack());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment