Advertisement
Guest User

Untitled

a guest
Jan 18th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.InputStreamReader;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8.  
  9. import android.app.Activity;
  10. import android.app.ProgressDialog;
  11. import android.os.AsyncTask;
  12. import android.os.Bundle;
  13. import android.view.Menu;
  14.  
  15. public class MainActivity extends Activity {
  16.  
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.activity_main);
  21.        
  22.         //Initializing the globals
  23.         Globals.mainActivity = this;
  24.         Globals.ip = "192.168.178.53:9001";
  25.         if(Globals.shopCon == null){
  26.             final ProgressDialog p = ProgressDialog.show(MainActivity.this, "", "Loading...");
  27.  
  28.            
  29.             class initConnection extends AsyncTask<Void, Void, Void>{
  30.                 protected Void doInBackground(Void... nothing){
  31.                     Globals.shopCon=new ShopConnection("http://" + Globals.ip + "/ws410/rest/");
  32.                    
  33.                    
  34.                     return null;                   
  35.                 }
  36. protected void onPostExecute(Void result)
  37. {
  38. super.onPostExecute(result);
  39. p.dismiss();
  40. }
  41.             }
  42.            
  43.             new initConnection().execute();
  44.         }
  45.     }
  46.     public String getXmlFromUrl(String sUrl){
  47.         InputStream is = null;
  48.         URLConnection conn = null;
  49.         URL pURL = null;
  50.         InputStreamReader isr = null;
  51.         BufferedReader in  = null;
  52.        
  53.         String strFileContents = new String("");
  54.         try{
  55.             String user = "admin:nimda";
  56.             String base64 = Globals.Base64(user);
  57.             pURL = new URL(sUrl);
  58.             if(pURL != null) conn = pURL.openConnection();
  59.             if(conn != null){
  60.                 conn.setRequestProperty("Authorization", base64);
  61.                  is = conn.getInputStream();
  62.             }
  63.  
  64.             if(is != null) isr = new InputStreamReader(is);
  65.             if(isr != null) in=new BufferedReader(isr);
  66.            
  67.             if(in != null){
  68.                 String data = new String("");
  69.                 while((data = in.readLine()) != null)
  70.                 {
  71.                     strFileContents += data;
  72.                 }
  73.                 in.close();
  74.             }
  75.         }catch(MalformedURLException e){
  76.             e.printStackTrace();
  77.         }catch(IOException e){
  78.             e.printStackTrace();
  79.         }
  80.         return strFileContents;
  81.     }
  82.     @Override
  83.     public boolean onCreateOptionsMenu(Menu menu) {
  84.         // Inflate the menu; this adds items to the action bar if it is present.
  85.         getMenuInflater().inflate(R.menu.activity_main, menu);
  86.         return true;
  87.     }
  88.  
  89. }
  90.  
  91.  
  92. ___________________________________________________________________________________________________________
  93. NEW FILE; NEW FILE; NEW FILE
  94. Globals.java, class Globals, only included is the function that is named in my source...
  95. _______________________________________
  96.     static public String Base64(String clear){
  97.         String crypt = new String("");
  98.         byte[] byteArray = null;
  99.         try {
  100.             byteArray = clear.getBytes("UTF-16");
  101.         } catch (UnsupportedEncodingException e) {
  102.             e.printStackTrace();
  103.         }
  104.         if(byteArray !=null) crypt = Base64.encodeToString(byteArray, Base64.DEFAULT);
  105.         return crypt;
  106.     }
  107. _________________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement