Guest User

Untitled

a guest
Dec 5th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. package com.tml.GVBabble;
  2.  
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5.  
  6. import org.apache.http.client.HttpClient;
  7. import org.json.JSONArray;
  8. import org.json.JSONException;
  9. import org.json.JSONObject;
  10.  
  11. import com.techventus.server.voice.Voice;
  12. import android.app.Activity;
  13. import android.os.Bundle;
  14. import android.widget.TextView;
  15.  
  16. public class GVBabbleActivity extends Activity {
  17.     /** Called when the activity is first created. */
  18.    
  19.     String userName = <username.;
  20.     String pass = <password>;
  21.     String phoneNumber = <phonenumber>;
  22.     TextView tvDisplay;
  23.     Voice voice;
  24.    
  25.     HttpClient client;
  26.     JSONObject json;
  27.    
  28.     JSONArray ja;
  29.     JSONObject jo;
  30.    
  31.     @Override
  32.     public void onCreate(Bundle savedInstanceState) {
  33.         super.onCreate(savedInstanceState);
  34.         setContentView(R.layout.main);
  35.        
  36.         tvDisplay = (TextView)findViewById(R.id.tvDisplay);
  37.        
  38.         try {
  39.             voice = new Voice(userName, pass);
  40.         } catch (IOException e) {
  41.             // TODO Auto-generated catch block
  42.             e.printStackTrace();
  43.         }
  44.        
  45.         String page = "";
  46.        
  47.         try {
  48.             page = voice.getInbox();
  49.         } catch (IOException e) {
  50.             // TODO Auto-generated catch block
  51.             e.printStackTrace();
  52.         }
  53.        
  54.         page = page.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", "");
  55.         page = page.replace("<response>\n", "");
  56.         page = page.replace("  <json><![CDATA", "");
  57.        
  58.         ArrayList<String> listItems = new ArrayList<String>();
  59.        
  60.         try{
  61.            
  62.             while (page != "") {
  63.                 ja = new JSONArray(page);
  64.  
  65.                 for (int i = 0; i < ja.length(); i++) {
  66.                     jo = (JSONObject) ja.get(i);
  67.                     listItems.add(jo.getString("displayNumber"));
  68.                 }
  69.             }
  70.         } catch (JSONException e) {
  71.             // TODO Auto-generated catch block
  72.             e.printStackTrace();
  73.         }
  74.        
  75.         for (int i=0; i<listItems.size(); i++){
  76.             tvDisplay.append(listItems.get(i) + "\n");
  77.         }
  78.        
  79.     }
  80. }
Add Comment
Please, Sign In to add comment