2016-11-03 2 views
0

내 응용 프로그램에 대한 새 업데이트를 사용자에게 알리기 위해 textFile 접근 방식을 사용하려고합니다. 나는 Playstore와 Google 드라이브에 앱을 가지고있다. 프로그래밍 방식으로 내 앱용 버전 코드를 얻는 데 성공했습니다. 문제는 Google 드라이브에서 호스팅 한 텍스트 파일에서 버전 코드를 읽는 것입니다.url에서 텍스트 파일 읽기 android

다음 코드를 발견했지만 Google 드라이브에서 내 URL을 사용할 때 아무 것도 반환하지 않습니다. 내가 놓친 게 있니?

private static String getUrlContents(String theUrl) 
{ 
    StringBuilder content = new StringBuilder(); 

    // many of these calls can throw exceptions, so i've just 
    // wrapped them all in one try/catch statement. 
    try 
    { 
     // create a url object 
     URL url = new URL(theUrl); 

     // create a urlconnection object 
     URLConnection urlConnection = url.openConnection(); 

     // wrap the urlconnection in a bufferedreader 
     BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); 

     String line; 

     // read from the urlconnection via the bufferedreader 
     while ((line = bufferedReader.readLine()) != null) 
     { 
      content.append(line + "\n"); 
     } 
     bufferedReader.close(); 
    } 
    catch(Exception e) 
    { 
     e.printStackTrace(); 
    } 
    return content.toString(); 
} 
+0

'새로운 update' 사용자에게 알리기 위해 TEXTFILE 접근 방식을 사용합니다. ??? 그게 뭐야? 절대 들어 본적이 없어. – greenapps

+0

기본적으로 응용 프로그램의 버전 코드가 들어있는 서버에 텍스트 파일을 호스팅합니다. 사용자가 애플리케이션을 실행하면 앱은 온라인으로 호스팅되는 파일의 버전 코드를 확인하고 프로그래밍 방식으로 얻을 수있는 앱의 현재 버전 코드와 비교합니다. 코드 버전이 동일하지 않다면 업데이트 프롬프트가 표시된 경고 대화 상자가 열리고 사용자가 '업데이트'를 클릭하면 Google 드라이브에 호스팅 된 앱에 직접 가져옵니다. – RynohRR

+0

'content.append ("Exception :"+ e .getMessage() + "\ n");'. 캐치 블록에 넣으십시오. – greenapps

답변

0

나는 (코멘트에서 제안) 나는 다른 게시물에 해결책을 찾은 것 같아 :

추가했습니다 다음 onCreate 기능

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 

StrictMode.setThreadPolicy(policy); 

. manifestFile에

그리고 이것은 :

<uses-permission android:name="android.permission.INTERNET"/>