Created
September 15, 2016 21:42
-
-
Save samjarman/9140e9b5f5e69e0e62c93ff1f34af614 to your computer and use it in GitHub Desktop.
This lets you set a custom user agent.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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