2011-09-08 44 views
0

我创建了一个方法来测试,如果以实时流的链接是主动或不使用下面的代码的iOS。目标C到Android XML响应

NSError * error = nil; 
NSString * responseString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime"] encoding:NSUTF8StringEncoding error:&error];  

NSRange range = [responseString rangeOfString : @"true"]; 

if (range.location != NSNotFound) { 
    NSLog(@"%@", responseString); \ 
    // Handle active content. 
    hiddenVideo.hidden = FALSE; 
    hiddenAudio.hidden = FALSE; 
    noService.hidden = TRUE; 
    } 
    else { 
     NSLog(@"%@", responseString); 
     // Inform user that the content is unavailable 
     hiddenVideo.hidden = TRUE; 
     hiddenAudio.hidden = TRUE; 
     noService.hidden = FALSE; 
     UIAlertView *alert = [[UIAlertView alloc] 
           initWithTitle: @"Live Service" 
          message: @"There is no service going on at this time" 
          delegate: nil 
          cancelButtonTitle:@"OK" 
          otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
     HasShownAlert = TRUE; //let the other event know that the alert has already been shown. 
    } 

问题是,我不知道从哪里开始将此转换为Android,我正在寻找一些指导。感谢您的帮助。

+1

从这里开始:http://developer.android.com/,例如代替UIAlertView中,你可能会被使用'android.app.AlertDialog' – Joe

+0

谢谢乔!这确实是有道理的 –

回答

1

我不知道在所有的目标C,但据我能够理解你只是从HTTP响应从服务器读取结果,并分析它。 要发送HTTP GET和读取响应:

HttpClient httpclient = new DefaultHttpClient(httpParameters); 
    HttpGet httpget = new HttpGet(url); 
    httpget.addHeader("If-Modified-Since", lastModified); 
    HttpResponse response; 
    response = httpclient.execute(httpget); 
    String result = null; 
    if(response.getStatusLine().getStatusCode() == 200) { 
     HttpEntity entity = response.getEntity(); 
     if (entity != null) { 
      InputStream instream = entity.getContent(); 
      //here read contents of stream 
     } 
    }