The previous article uses the Properties read-write configuration, various path errors, or no write permissions.
Later check the data, use another way to read and write Sharedpreferencesimpl
Direct Sticker Code
public class--Read and write
Packagecom.lemon.demo.utils;ImportAndroid.content.Context;Importandroid.content.SharedPreferences;ImportAndroid.util.Log; Public classUrlconfig {Private Staticsharedpreferences share; Private StaticString Configpath = "AppConfig"; Public Staticsharedpreferences getProperties (context context) {Try{Share=context.getsharedpreferences (Configpath, context.mode_private); } Catch(Exception e) {e.printstacktrace (); } returnshare; } Public Staticstring SetProperties (context context, string keyName, String keyValue) {Try{Share=context.getsharedpreferences (Configpath, context.mode_private); Sharedpreferences.editor Editor= Share.edit ();//Get editorEditor.putstring (KeyName, KeyValue);//The storage configuration parameter 1 is the key parameter 2 is the valueEditor.commit ();//Submit Refresh Data } Catch(Exception e) {e.printstacktrace (); LOG.E ("Setpropertieserror", e.tostring ()); return"Failed to modify configuration file!"; } return"Setup succeeded"; }}
Packaging
PackageCom.lemon.demo.json;ImportAndroid.content.Context;Importandroid.content.SharedPreferences;ImportCom.lemon.demo.utils.UrlConfig;/*** Network Request*/ Public classurlstring { Private Static FinalString IP = "192.168.1.10:8000"; PrivateString contrastipname = "Contrastip"; //Upload Path PrivateString IP; PrivateString ipAddress; Public voidsetipaddress (Context context) {//Properties proper = properties.getproperties (context); //This.ip = Proper.getproperty (Contrastipname, "");Sharedpreferences proper =urlconfig.getproperties (context); This. IP = proper.getstring (contrastipname, ""); //Set Default values if( This. Ip.equals ("")){ This. IP =IP; } This. ipAddress = "http://" + This. IP + "/v1.0/index.html"; } Publicstring Setipaddress (context context, String KeyValue) {//String result = properties.setproperties (context, contrastipname, keyValue);String result =urlconfig.setproperties (context, contrastipname, keyValue); This. IP =KeyValue; This. ipAddress = "http://" + This. IP + "/v1.0/index.html"; returnresult; } PublicString GetIP () {return This. IP; } PublicString getipaddress () {return This. ipAddress; }}
How to use the same article.
Reference: HTTP://WWW.JIANSHU.COM/P/87024CE283C9
Reference: http://leequer.iteye.com/blog/654942
Android read/write Configuration 2