1

I know my question is worded somewhat confusingly, but...

My app is using an instant messaging SDK called Applozic. In order to hide/add certain features into the UI, there is an applozic-settings.json file which can be edited.

For example: "hideGroupExitButton": true

My app has two types of users: senders and receivers. Senders have some capabilities that receivers do not... so I need to change some of these values depending on the user type.

SO: is it possible to programmatically change some of these values based on user type?

(applozic-settings.json is only used in FileUtils.java-- which is a LOCKED file...)

Or, do I need to create a new json file for one of the user types, and somehow change FileUtils.java to use the proper file?

This is the relevant code in FileUtils.java:


public static String loadSettingsJsonFile(Context context) {
    BufferedReader br = null;
    StringBuffer sb = new StringBuffer();
    try {
        br = new BufferedReader(new InputStreamReader(context.getAssets().open(
                "applozic-settings.json"), "UTF-8"));
        String line;
        if (br != null) {
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
        }
    } catch (IOException ioe) {
        return null;
    } catch (Exception e) {
    } finally {
        try {
            if (br != null) {
                br.close();
            }
        } catch (IOException e) {
        }
    }
    return sb.toString();
}

Vanessa
  • 61
  • 3
  • 1
    I recommend the JsonSimple library if you want to easily read/write JSON files using Java. Intro: https://mkyong.com/java/json-simple-example-read-and-write-json/ Jar Download: https://code.google.com/archive/p/json-simple/ – Tim Hunter Jan 28 '20 at 19:17
  • We have some settings in ApplozicSetting.java that you can set programmatically in code you can find the settings in that file. If any of the settings you would like to add that you can connect us at applozic support email support@applozic.com – Sunil Kumar Jan 31 '20 at 07:06

1 Answers1

2

If I understand correctly, it is possible to edit the values of a JSON file. See: JSON File - Java: editing/updating fields values

If you wanted to open a different file based on the user, just store the different files in strings for example here:

br = new BufferedReader(new InputStreamReader(context.getAssets().open(
                "applozic-settings.json"), "UTF-8"));

You could simply say string file = "applozic-settings.json";

and directly pass it into the function above:

br = new BufferedReader(new InputStreamReader(context.getAssets().open(
                file), "UTF-8"));

So in essence you could say:

string file;
if(userType == x){
   file="x.json"
}
else{
   file="y.json"
}

ty1
  • 334
  • 4
  • 19