美文网首页android系统应用开发
修改系统语言,NTF服务器

修改系统语言,NTF服务器

作者: Ayugone | 来源:发表于2019-06-13 14:49 被阅读0次

    /*********修改系统语言,不需要重启**********/
    public static void setLanguage(Locale locale) {
    try {
    Object objIActMag;

            Class clzIActMag = Class.forName("android.app.IActivityManager");
    
            Class clzActMagNative = Class
                    .forName("android.app.ActivityManagerNative");
    
            Method mtdActMagNative$getDefault = clzActMagNative
                    .getDeclaredMethod("getDefault");
    
            objIActMag = mtdActMagNative$getDefault.invoke(clzActMagNative);
    
            Method mtdIActMag$getConfiguration = clzIActMag
                    .getDeclaredMethod("getConfiguration");
    
            Configuration config = (Configuration) mtdIActMag$getConfiguration
                    .invoke(objIActMag);
    
            config.locale = locale;
    
            Class clzConfig = Class
                    .forName("android.content.res.Configuration");
            java.lang.reflect.Field userSetLocale = clzConfig
                    .getField("userSetLocale");
            userSetLocale.set(config, true);
    
            Class[] clzParams = { Configuration.class };
    
            Method mtdIActMag$updateConfiguration = clzIActMag
                    .getDeclaredMethod("updateConfiguration", clzParams);
    
            mtdIActMag$updateConfiguration.invoke(objIActMag, config);
    
            BackupManager.dataChanged("com.android.providers.settings");
    
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    /********获取和修改NTF服务*********/
    private String getNTPServer() {
    return Settings.Global.getString(getContentResolver(),Settings.Global.NTP_SERVER);
    }

    Settings.Global.putString(getContentResolver(),Settings.Global.NTP_SERVER,sci.getNtp_server());

    相关文章

      网友评论

        本文标题:修改系统语言,NTF服务器

        本文链接:https://www.haomeiwen.com/subject/doksfctx.html