daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class SelectUni extends ListActivity {
  2.  
  3. // URL to get contacts JSON
  4. private static String URL2 = "http://echo.jsontest.com/key/value/one/two";
  5.  
  6. @Override
  7. protected void onCreate(Bundle savedInstanceState) {
  8.     super.onCreate(savedInstanceState);
  9.     getListView().setBackgroundColor(Color.rgb(255, 255, 255));
  10.  
  11.     try {
  12.         Log.d("URL", new URL(URL2).toString());
  13.     } catch (MalformedURLException e) {
  14.         e.printStackTrace();
  15.     }
  16.     try {
  17.         new URL(URL2).openConnection().connect();
  18.     } catch (IOException e) {
  19.         e.printStackTrace();
  20.     }
  21.  
  22.     //Log.d("TEST", getJSON(URL2));
  23.  
  24.  
  25.     String[] test = {"sd", "nsdkh", "sdkjf", "!", "hjsbdf", "jksd", "skdhg", "hdvgb", "dmhsdf", "sjhfg", "jksd", "skdhg", "hdvgb", "dmhsdf", "sjhfg"};
  26.     Arrays.sort(test);
  27.  
  28.     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
  29.             android.R.layout.simple_list_item_1, test);
  30.     setListAdapter(adapter);
  31.  
  32.  
  33. }
  34.  
  35.  
  36. public static String getJSON(String url) {
  37.     HttpsURLConnection con = null;
  38.     try {
  39.         URL u = new URL(url);
  40.         con = (HttpsURLConnection) u.openConnection();
  41.  
  42.         con.connect();
  43.  
  44.  
  45.         BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
  46.         StringBuilder sb = new StringBuilder();
  47.         String line;
  48.         while ((line = br.readLine()) != null) {
  49.             sb.append(line + "n");
  50.         }
  51.         br.close();
  52.         return sb.toString();
  53.  
  54.  
  55.     } catch (MalformedURLException ex) {
  56.         ex.printStackTrace();
  57.     } catch (IOException ex) {
  58.         ex.printStackTrace();
  59.     } finally {
  60.         if (con != null) {
  61.             try {
  62.                 con.disconnect();
  63.             } catch (Exception ex) {
  64.                 ex.printStackTrace();
  65.             }
  66.         }
  67.     }
  68.     return null;
  69. }
RAW Paste Data
Top