如何从远程服务器检索字符串?
答
你有没有考虑过使用SQLite数据库来存储这些字符串?
回答你的问题。是的,可以从远程服务器检索字符串,只要您在服务器端有适当的代码,以XML/JSON.etc的形式返回指定的字符串(比如使用ID)。
一旦你得到结果回来,解析响应得到的字符串。下面是一个示例代码:
private String _mStringURL = "http://yourserver.com/getString.php?string_id=<a unique id>&language=<languagecode>";
url = new URL(statusURL);
URLConnection connection;
connection = url.openConnection();
//Get data and check to see if everything was OK. Set time out to 10 secs.
HttpURLConnection httpConnection = (HttpURLConnection) connection;
httpConnection.setConnectTimeout(10*1000);
int responseCode = httpConnection.getResponseCode();
//Proceed if everything went OK in communication.
if(responseCode == HttpURLConnection.HTTP_OK){
InputStream in = httpConnection.getInputStream();
DocumentBuilderFactory dbf;
dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(in);
Element docEle = dom.getDocumentElement();
NodeList nl = docEle.getElementsByTagName("string");
//Your code to further parse and access teh data from return XML/JSON goes here.
}
答
为您的编程语言研究国际化解决方案。您可以简单地使用它来外化您的字符串,而不是用它来翻译您的应用程序。只需让程序从服务器上拉下.mo/.ini(或者系统使用的任何文件)即可。
请记住,这是有风险的。如果用户没有互联网连接,您的应用程序将完全无法使用。
你使用什么编程语言?我可以将你链接到一个教程。
您要保存多少个字符串? – 2011-12-31 18:01:39
您可以将它作为一个XML并从网上解析它的值。 – Karthik 2011-12-31 18:02:40
你能给我一个这个教程的链接吗? – Leon 2011-12-31 18:04:11