我有一個應用程序,我從每個 OkHTTP 的網絡服務器獲取一些值,它可以工作并將其顯示在 MainActivity 上?,F在我想將這些收到的值添加到network_security_config.xml.為了簡單起見,我在 MainActivity 中設置一個 String 等于YZPgTZ+woNCCCIW3LH2CxQeLzB/1m42QcCTBSdgayjs=現在我希望這個字符串出現在我的network_security_config.xmlat中VALUE_I_WANT_TO_ADD。我該怎么做呢?我可以為此使用 jdom 嗎?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>
1 回答

縹緲止盈
TA貢獻2041條經驗 獲得超4個贊
從你的問題看來,你想保存你的字符串以備后用,所以你可以使用SharedPreferences來保存String以備后用。
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();
稍后,您可以SharedPreferences在再次運行您的應用程序時檢索您的字符串,如下所示
String value = sharedPref.getString("key","default_value");
添加回答
舉報
0/150
提交
取消