2014-04-21 74 views
-1

我正在開發Android應用程序。我已將我的應用程序連接到寧靜的Web服務。每當我連接我的網絡時,我的IP地址被更改。所以我想設置靜態IP地址。但我試圖通過網絡共享屬性靜態IP地址。但它不起作用。任何人都可以幫助我?如何爲android web應用設置靜態IP地址?

+2

在** **粗體字體並不能真正幫助使問題得到答案。 –

+0

這個問題是題外話題,因爲它涉及到網絡,並沒有直接涉及到編程。 –

+0

@ Log1c剛剛編輯:) –

回答

0

您可以嘗試類似代碼:

public static final String URLPREFIX = "http://url/api"; 
     HttpGet httpget = new HttpGet(URLPREFIX + "/method_name/token/" 
       + mAuthKey); 
     Log.e(TAG, "" + URLPREFIX + "/method_name/token/" + mAuthKey); 
     try { 

      // Execute HTTP Post Request 
      HttpResponse response = httpclient.execute(httpget); 
      HttpEntity entity = response.getEntity(); 

      String jsonResponse = EntityUtils.toString(entity); 
      Log.e(TAG, "entity: " + jsonResponse); 

      JSONObject jsonObject = new JSONObject(jsonResponse); 
      JSONArray jsonArray = jsonObject.getJSONArray("collection"); 
      for (int i = 0; i < jsonArray.length(); i++) { 
       JSONObject mFirstChild = jsonArray.getJSONObject(i); 
       int mId = Integer.parseInt(mFirstChild.getString("id")); 
       String mTitle = mFirstChild.getString("title"); 
       arrayList.add(new CustomClass(mId, mTitle)); 

      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     }