Android Utililty Methods Context Set

List of utility methods to do Context Set

Description

The list of methods to do Context Set are organized into topic(s).

Method

voidsetLanguage(Context context, String language)
set Language
Locale locale;
if (TextUtils.isEmpty(language)) {
    locale = Locale.getDefault();
} else if (language.length() == 5 && language.charAt(2) == '_') {
    locale = new Locale(language.substring(0, 2),
            language.substring(3));
} else {
    locale = new Locale(language);
...
voidsetProxy(Context ctx)
set Proxy
setProxy(ctx, DEFAULT_HOST, DEFAULT_PORT);
booleansetProxy(Context ctx, String host, int port)
set Proxy
setSystemProperties(host, port);
boolean worked = false;
if (Build.VERSION.SDK_INT < 14) {
    worked = setWebkitProxyGingerbread(ctx, host, port);
} else {
    worked = setWebkitProxyICS(ctx, host, port);
return worked;
...
voidsetRevokedPermissions(String packageName, String[] permissions, Context ctx)
set Revoked Permissions
PackageManager pkgManager = ctx.getPackageManager();
Method setRevokedPermissions;
try {
    setRevokedPermissions = pkgManager.getClass().getMethod(
            "setRevokedPermissions", java.lang.String.class,
            String[].class);
    Object[] params = new Object[] { packageName, permissions };
    setRevokedPermissions.invoke(pkgManager, params);
...
booleansetWebkitProxyGingerbread(Context ctx, String host, int port)
Override WebKit Proxy settings
boolean ret = false;
Object requestQueueObject = getRequestQueue(ctx);
if (requestQueueObject != null) {
    HttpHost httpHost = new HttpHost(host, port, "http");
    setDeclaredField(requestQueueObject, "mProxyHost", httpHost);
    return true;
return false;
...
booleansetWebkitProxyICS(Context ctx, String host, int port)
set Webkit Proxy ICS
try {
    Class webViewCoreClass = Class
            .forName("android.webkit.WebViewCore");
    Class proxyPropertiesClass = Class
            .forName("android.net.ProxyProperties");
    if (webViewCoreClass != null && proxyPropertiesClass != null) {
        Method m = webViewCoreClass.getDeclaredMethod(
                "sendStaticMessage", Integer.TYPE, Object.class);
...
voidsetWelcomeShown(final Context ctx)
set Welcome Shown
ctx.getSharedPreferences("_welcome_dialog_shown",
        Context.MODE_PRIVATE).edit().putBoolean("shown", true)
        .commit();