下面列出了android.content.Context#MODE_PRIVATE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Uri getApkUri(String path) {
// Before N, a MODE_WORLD_READABLE file could be passed via the ACTION_INSTALL_PACKAGE
// Intent. Since N, MODE_WORLD_READABLE files are forbidden, and a FileProvider is
// recommended.
boolean useFileProvider = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
// String tempFilename = "tmp.apk";
// byte[] buffer = new byte[16384];
int fileMode = useFileProvider ? Context.MODE_PRIVATE : Context.MODE_WORLD_READABLE;
/* try (InputStream is = new FileInputStream(new File(path));
FileOutputStream fout = context.openFileOutput(tempFilename, fileMode)) {
int n;
while ((n = is.read(buffer)) >= 0) {
fout.write(buffer, 0, n);
}
} catch (IOException e) {
Log.i(TAG + ":getApkUri", "Failed to write temporary APK file", e);
}*/
if (useFileProvider) {
// File toInstall = new File(context.getFilesDir(), tempFilename);
File toInstall = new File(path);
return FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID+".provider", toInstall);
} else {
return Uri.fromFile(new File(path));
}
}
/**
* 保存基本配置
* @param context
* @return
*/
public static ClanConfig getConfig(Context context) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_PREFERENCES, Context.MODE_PRIVATE);
ClanConfig clanConfig = new ClanConfig();
clanConfig.setApiUrl(sharedPreferencesUtils.loadStringSharedPreference(Key.CLAN_CONFIG_DOMAIN));
clanConfig.setApiUrlBase(sharedPreferencesUtils.loadStringSharedPreference(Key.CLAN_CONFIG_BASE));
clanConfig.setApiUrlRealBase(sharedPreferencesUtils.loadStringSharedPreference(Key.CLAN_CONFIG_REAL_BASE));
clanConfig.setAppId(sharedPreferencesUtils.loadStringSharedPreference(Key.CLAN_CONFIG_APP_ID));
clanConfig.setAppKey(sharedPreferencesUtils.loadStringSharedPreference(Key.CLAN_CONFIG_APP_KEY));
AdUrl adUrl = new AdUrl();
adUrl.setUrlSplashAd(sharedPreferencesUtils.loadStringSharedPreference(Key.CLAN_CONFIG_AD_SPLASH));
adUrl.setUrlListAd(sharedPreferencesUtils.loadStringSharedPreference(Key.CLAN_CONFIG_AD_LIST));
adUrl.setUrlLogAd(sharedPreferencesUtils.loadStringSharedPreference(Key.CLAN_CONFIG_AD_LOG));
clanConfig.setAd(adUrl);
LoginInfo loginInfo = new LoginInfo();
loginInfo.setLoginMod(sharedPreferencesUtils.loadIntSharedPreference(Key.APP_CONFIG_LOGIN_MODE));
loginInfo.setLoginUrl(sharedPreferencesUtils.loadStringSharedPreference(Key.APP_CONFIG_LOGIN_URL));
loginInfo.setRegMod(sharedPreferencesUtils.loadIntSharedPreference(Key.APP_CONFIG_REG_MODE));
loginInfo.setRegUrl(sharedPreferencesUtils.loadStringSharedPreference(Key.APP_CONFIG_REG_URL));
loginInfo.setRegSwitch(sharedPreferencesUtils.loadIntSharedPreference(Key.APP_CONFIG_REG_SWITCH));
loginInfo.setAllowAvatarChange(sharedPreferencesUtils.loadStringSharedPreference(Key.APP_CONFIG_ALLOW_AVATAR_CHANGE));
clanConfig.setLoginInfo(loginInfo);
clanConfig.setAppStyle(sharedPreferencesUtils.loadIntSharedPreference(Key.APP_CONFIG_APP_STYLE));
return clanConfig;
}
public static void saveContentConfig(Context context, ContentConfig clanConfig) {
if (clanConfig == null)
return;
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_CONFIG_FORUM_DISPLAY_STYLE, clanConfig.getDisplayStyle());
if (clanConfig.getPlatformLogin() == null) {
clanConfig.setPlatformLogin(new PlatformLogin());
}
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_CONFIG_QQ_LOGIN, clanConfig.getPlatformLogin().getQQLogin());
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_CONFIG_QQ_LOGIN_END, clanConfig.getPlatformLogin().getQQloginEnd());
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_CONFIG_WECHAT_LOGIN, clanConfig.getPlatformLogin().getWechatLogin());
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_CONFIG_WEIBO_LOGIN, clanConfig.getPlatformLogin().getWeiboLogin());
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_CONFIG_CHECKINENABLED, clanConfig.getCheckinEnabled());
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_CONFIG_IYZVERSOIN, clanConfig.getIyzversion());
if (clanConfig.getSmileyInfo() != null) {
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_SIMILY_INFO_ZIP_LAST_MD5, getContentConfig(context).getSmileyInfo().getMD5());
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_SIMILY_INFO_ZIP_MD5, clanConfig.getSmileyInfo().getMD5());
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_SIMILY_INFO_ZIP_URL, clanConfig.getSmileyInfo().getZipUrl());
} else {
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_SIMILY_INFO_ZIP_LAST_MD5, "");
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_SIMILY_INFO_ZIP_MD5, "");
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_SIMILY_INFO_ZIP_URL, "");
}
if (clanConfig.getSearchSetting() != null) {
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_SEARCH_SETTING, JsonUtils.toJSONString(clanConfig.getSearchSetting()));
}
if (clanConfig.getThreadConfig() != null) {
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_THREAD_SETTING, JsonUtils.toJSONString(clanConfig.getThreadConfig()));
}
if (clanConfig.getPortalconfig() != null) {
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_PORTAIL_SETTING, JsonUtils.toJSONString(clanConfig.getPortalconfig()));
}
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_APP_DESC, clanConfig.getAppDesc());
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_PUSH_ENABLED, clanConfig.getPushEnabled());
}
private static int getDefaultSharedPreferencesMode() {
return Context.MODE_PRIVATE;
}
public static void saveEnableScrollViewPager(Context context, boolean b) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferencesUtils.saveSharedPreferences("is_enable_scroll_viewpager", b);
}
private static int getDefaultSharedPreferencesMode() {
return Context.MODE_PRIVATE;
}
public static void saveUMainStyle(Context context, int style) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferencesUtils.saveSharedPreferences(Key.KEY_U_MAIN_STYLE, style);
}
public static void saveUShowBadge(Context context, boolean isUJpush) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferencesUtils.saveSharedPreferences(Key.KEY_U_SHOW_BADGE, isUJpush);
}
public static boolean isTail(Context context) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
return sharedPreferencesUtils.loadBooleanSharedPreference("IS_TAIL", false);
}
public static int getUThemeColor(Context context) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
return sharedPreferencesUtils.loadIntSharedPreference(Key.KEY_U_THEME_COLOR, 0);
}
public static void saveUShowDigetstInTitle(Context context, boolean isUJpush) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferencesUtils.saveSharedPreferences(Key.KEY_U_SHOW_DIGETST_IN_TITLE, isUJpush);
}
public static void saveSmileyLastMD5(Context context, String lastMD5) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_CONTENT_SIMILY_INFO_ZIP_LAST_MD5, lastMD5);
}
private static int getDefaultSharedPreferencesMode() {
return Context.MODE_PRIVATE;
}
public static boolean isLookPicSize(Context context) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
return sharedPreferencesUtils.loadBooleanSharedPreference("IS_LOOK_PIC_SIZE", false);
}
public static boolean isZhaoMode(Context context) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
return sharedPreferencesUtils.loadBooleanSharedPreference("ZHAO_MODE", false);
}
public static boolean isPicSize(Context context) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
return sharedPreferencesUtils.loadBooleanSharedPreference("IS_PIC_SIZE", false);
}
public static void saveHomePageConfigJson(Context context, String clanHomePagerConfigJson) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferencesUtils.saveSharedPreferences(Key.CLAN_HOME_PAGE_CONFIG, clanHomePagerConfigJson);
}
public static void savePicSize(Context context, boolean b) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferencesUtils.saveSharedPreferences("IS_PIC_SIZE", b);
}
public static boolean isUShowGroupAndRegisterDate(Context context) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
return sharedPreferencesUtils.loadBooleanSharedPreference(Key.KEY_U_SHOW_GROUP_AND_REGISTER_DATE, false);
}
public static void saveZhaoMode(Context context, boolean b) {
SharedPreferencesUtils sharedPreferencesUtils = new SharedPreferencesUtils(context, Key.FILE_USER_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferencesUtils.saveSharedPreferences("ZHAO_MODE", b);
}