Advertisement
Guest User

Untitled

a guest
May 4th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. public class Download extends AsyncTask<Void, Void, String> {
  2.  
  3.  
  4. protected String doInBackground(Void... params) {
  5.  
  6. URL url = null;
  7. try {
  8. url = new URL( "http://dagobah.grifin.pt/tiagocoelho/Conexaotumg.php");
  9. } catch (MalformedURLException e) {
  10. e.printStackTrace();
  11. }
  12. HttpURLConnection conn = null;
  13. try {
  14. conn = (HttpURLConnection) url.openConnection();
  15. } catch (IOException e) {
  16. e.printStackTrace();
  17. }
  18. try {
  19. if( conn.getResponseCode() == HttpURLConnection.HTTP_OK ){
  20. InputStream is = conn.getInputStream();
  21.  
  22. }else{
  23. InputStream err = conn.getErrorStream();
  24.  
  25. }
  26. } catch (IOException e) {
  27. e.printStackTrace();
  28. }
  29. String out = null;
  30.  
  31. try {
  32. DefaultHttpClient httpClient = new DefaultHttpClient();
  33.  
  34. String url_all_empresas = "http://dagobah.grifin.pt/tiagocoelho/Conexaotumg.php";
  35.  
  36. final HttpParams httpParameters = httpClient.getParams();
  37.  
  38. HttpConnectionParams.setConnectionTimeout(httpParameters, 15000);
  39. HttpConnectionParams.setSoTimeout(httpParameters, 15000);
  40.  
  41. HttpGet httpPost = new HttpGet(url_all_empresas);
  42.  
  43. HttpResponse httpResponse = httpClient.execute(httpPost);
  44. HttpEntity httpEntity = httpResponse.getEntity();
  45.  
  46. out = EntityUtils.toString(httpEntity, HTTP.UTF_8);
  47.  
  48. } catch (UnsupportedEncodingException e) {
  49. e.printStackTrace();
  50. } catch (ClientProtocolException e) {
  51. e.printStackTrace();
  52. } catch (IOException e) {
  53. e.printStackTrace();
  54. }
  55.  
  56. return out;
  57. }
  58.  
  59. class btnsearchclicker implements Button.OnClickListener
  60. {
  61. @Override
  62. public void onClick(View v){
  63. AlertDialog.Builder b = new AlertDialog.Builder(MainActivity.this);
  64. b.setTitle(overflow2);
  65.  
  66. b.setItems((overflow.toArray(new String[linhas.size()])), new DialogInterface.OnClickListener() {
  67.  
  68. @Override
  69. public void onClick(DialogInterface dialog, int which) {
  70.  
  71. dialog.dismiss();
  72. int j = 0;
  73.  
  74. for (j = 0; j <= overflow.size(); j++) {
  75. if (j == which) {
  76.  
  77. btnstackoverflow.setText(overflow.get(j));
  78.  
  79.  
  80. }
  81. }
  82.  
  83. }
  84. });
  85. b.show();
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement