I have an app I get some values from a webserver per OkHTTP, which works and it displays it on MainActivity. Now I want to add those recieved values to network_security_config.xml.
For simplicity sakes, I set a String in MainActivity to be equal to YZPgTZ+woNCCCIW3LH2CxQeLzB/1m42QcCTBSdgayjs=
Now I want this string to appear in my network_security_config.xml at VALUE_I_WANT_TO_ADD. How do I do this? Could I maybe use jdom for this ?
network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">google.com</domain>
<pin-set expiration="2020-01-01">
<pin digest="SHA-256">MbZtXtN6X71CNe/UJzKFH0UGnPWGux5/zo5BRaJpkvI=</pin>
<pin digest="SHA-256">VALUE_I_WANT_TO_ADD</pin>
</pin-set>
</domain-config>
</network-security-config>
From your question it appears that you want to save your string for a later use, so you can use SharedPreferences to save the String for later use.
final String TAG = "some final text";
sharedPref = new SharedPreferences();
sharedPref = getSharedPreferences(TAG,Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("key","your_string");
editor.apply();
Later on, you can retreive your string from SharedPreferences when you run your app again as follows
String value = sharedPref.getString("key","default_value");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With