// TODO: Copy the file somewhere non-rooted, write, replace
public void saveProperties(UIProperties properties) {
try (Writer writer = new FileWriter(FILEPATH)) {
// Serialize the UIProperties object to JSON and write it to the file
gson.toJson(properties, writer);
Log.i(TAG, "UI Properties saved to " + FILEPATH);
}
catch (IOException e) {
Log.e(TAG, "Could not save UI Properties to " + FILEPATH);
Log.e(TAG, e.getMessage());
}
}
// TODO: Copy the file somewhere non-rooted, read, use
public UIProperties loadProperties() {
try(Reader reader = new FileReader(FILEPATH)) {
// Deserialize the JSON from the file into a UIProperties object
UIProperties properties = gson.fromJson(reader, UIProperties.class);
// If the file exists but is empty or contains invalid JSON, fromJson might return null
if (properties == null) {
Log.e(TAG, "JSON file " + FILEPATH + " is empty or invalid. Returning new UIProperties.");
return new UIProperties();
}
return properties;
}
catch (IOException e) {
Log.e(TAG, "Could not load UI properties from " + FILEPATH);
Log.e(TAG, e.getMessage());
return new UIProperties();
}
catch (JsonSyntaxException e) {
Log.e(TAG, "Invalid JSON syntax in" + FILEPATH);
return new UIProperties();
}
}
< /code>
Как мне обойти разрешения в Android Studio, если у меня есть корневое устройство? Я хочу загрузить и сохранить файл JSON из каталога, который обычно требует корневого на Android 15. мое приложение, так что мне интересно, как я могу это сделать.
Подробнее здесь: https://stackoverflow.com/questions/796 ... ed-devices
Как обойти разрешения на укорененные устройства ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение