2011-09-08 2 views
0

다음 코드를 사용하여 iOS에서 라이브 스트림에 대한 링크가 활성 상태인지 여부를 테스트하는 방법을 만들었습니다.Objective C to Android XML Response

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. 
    } 

문제는 안드로이드로 변환에서 어디서부터 시작 해야할지 모르겠지만 나는 약간의 지침을 찾고 있습니다. 도와 줘서 고마워.

+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 
     } 
    }