Friday, January 25, 2013
[Android] 版本字串比較
第一種
int OldVersion = Integer.parseInt( NabiFunction.getNabiVersion().replaceAll( "\\.", "" ) );
int NewVersion = Integer.parseInt( "1.9.20".replaceAll( "\\.", "" ) );
if(OldVersion < NewVersion){
Toast.makeText(AppZoneV2Activity.this, "Please Update", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(AppZoneV2Activity.this, "It is New Version", Toast.LENGTH_LONG).show();
}
將字串中的 "," 全部改成"" (使用replace方法)
EX: 1.9.20 ----> 1920
第二種
In Activity
private void CheckVersion(){
String NabiVersion = NabiFunction.getNabiVersion();
Out.println("NabiFunction.getNabiVersion()=" + NabiVersion,FuhuApplication.LOG_SWITCH);
String nabiversion[] = NabiVersion.split("\\.");
if(Integer.parseInt(nabiversion[0]) < 2){
if(Integer.parseInt(nabiversion[1]) < 10){
if(Integer.parseInt(nabiversion[2]) < 21){
// Toast.makeText(AppZoneV2Activity.this, "Please Update", Toast.LENGTH_LONG).show();
CheckVersionWarning();
}
}
}
}
以 ","為分割點
逐次丟入陣列之中
然後再一次一次的比較
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment