如果有这样的问题,我很抱歉 我只想知道,我正在尝试在服务器上读取文件.txt并转换为int和 我尝试使用froyo模拟器时取得了成功
这是我的代码
final Context context = this;
TextView textServer, textApp;
final String textSource = "http://xxx/dev/android/androidversi.txt";
宣传.txt文件的位置
URL textUrl;
String StringBuffer;
String stringText = "";
try {
textUrl = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(textUrl.openStream()));
while ((StringBuffer = bufferReader.readLine()) != null)
{
stringText += StringBuffer;
}
bufferReader.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
上面的代码阅读.txt来自服务器的文件和这个代码因为我在JROY BEAN中犯了错误,因为我已经在FROYO正常运行
PackageManager manager = getPackageManager();
PackageInfo info;
try {
info = manager.getPackageInfo(getPackageName(), 0);
int version = info.versionCode;
if(Integer.parseInt(stringText)>version) // I'VE CONVERTED STRING FROM .txt TO INT SO THAT I CAN COMPARE IT WITH VERSION ON APP
{
// IF VERSION ON SERVER > VERSION APP THERE IS LINK TO DOWNLOAD HERE
}
} catch (NameNotFoundException e){
e.printStackTrace();
}
比较版本
请帮帮我:'(
答案 0 :(得分:0)
它只是主线程异常上的网络;只需加入
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
到您的代码(在onCreate()方法中),你会没事的:)