Updatestrings
Package Io. appium. android. bootstrap. handler; import Io. appium. android. bootstrap. androidcommand; import Io. appium. android. bootstrap. androidcommandresult; import Io. appium. android. bootstrap. commandhandler; import Io. appium. android. bootstrap. logger; import Java. io. datainputstream; import Java. io. file; import Java. io. fileinputstream; import Org. JSON. jsonobject;/*** this handler is used to update the APK strin GS. **/public class updatestrings extends commandhandler {/*** strings. the JSON file stores the strings of the APK. the content in XML is parsed by the appium server and pushed to the device ** @ return */public static Boolean loadstringsjson () {logger. debug ("loading JSON... "); try {final string filepath ="/data/local/tmp/strings. JSON "; final file jsonfile = new file (filepath); // JSON will not exist for apks that are only on device // your case is required The APK path must be specified. If the application on the device is started and the app path is not in case, the JSON file does not exist. // because the node server can't extract the JSON from the APK. if (! Jsonfile. exists () {return false;} final datainputstream datainput = new datainputstream (New fileinputstream (jsonfile); Final byte [] jsonbytes = new byte [(INT) jsonfile. length ()]; datainput. readfully (jsonbytes); // This closes fileinputstream datainput. close (); final string jsonstring = new string (jsonbytes, "UTF-8"); // assign the read information to properties in the find class, use find.apk strings = new jsonobject (jsonstring); log Ger. debug ("JSON Loading complete. ");} catch (final exception e) {logger. error ("error loading JSON:" + E. getmessage (); Return false;} return true;}/** @ Param command the {@ link androidcommand} used for this handler. ** @ return {@ link androidcommandresult} ** @ see Io. appium. android. bootstrap. commandhandler # execute (Io. appium. android. * Bootstrap. androidcommand) * // @ override public androidco Mmandresult execute (final androidcommand command) {If (! Loadstringsjson () {return geterrorresult ("unable to load JSON file and update strings.") ;}return getsuccessresult (true );}}
During appium initialization, if you add an app in your code instead of starting an existing app on your mobile phone, appium will parse the app, extracts strings from the current language environment of the device. the information in the XML file is stored in strings. JSON, and push it to the/data/local/tmp directory of the mobile phone. When you want to obtain the strings used in the application, the mobile phone will read strings in this directory. JSON file and return it to the client.
So the above Code is the process I mentioned above.
Updatestrings of Bootstrap