Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.view.Menu;
- public class MainActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- //Initializing the globals
- Globals.mainActivity = this;
- Globals.ip = "192.168.178.53:9001";
- if(Globals.shopCon == null){
- final ProgressDialog p = ProgressDialog.show(MainActivity.this, "", "Loading...");
- class initConnection extends AsyncTask<Void, Void, Void>{
- protected Void doInBackground(Void... nothing){
- Globals.shopCon=new ShopConnection("http://" + Globals.ip + "/ws410/rest/");
- return null;
- }
- protected void onPostExecute(Void result)
- {
- super.onPostExecute(result);
- p.dismiss();
- }
- }
- new initConnection().execute();
- }
- }
- public String getXmlFromUrl(String sUrl){
- InputStream is = null;
- URLConnection conn = null;
- URL pURL = null;
- InputStreamReader isr = null;
- BufferedReader in = null;
- String strFileContents = new String("");
- try{
- String user = "admin:nimda";
- String base64 = Globals.Base64(user);
- pURL = new URL(sUrl);
- if(pURL != null) conn = pURL.openConnection();
- if(conn != null){
- conn.setRequestProperty("Authorization", base64);
- is = conn.getInputStream();
- }
- if(is != null) isr = new InputStreamReader(is);
- if(isr != null) in=new BufferedReader(isr);
- if(in != null){
- String data = new String("");
- while((data = in.readLine()) != null)
- {
- strFileContents += data;
- }
- in.close();
- }
- }catch(MalformedURLException e){
- e.printStackTrace();
- }catch(IOException e){
- e.printStackTrace();
- }
- return strFileContents;
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.activity_main, menu);
- return true;
- }
- }
- ___________________________________________________________________________________________________________
- NEW FILE; NEW FILE; NEW FILE
- Globals.java, class Globals, only included is the function that is named in my source...
- _______________________________________
- static public String Base64(String clear){
- String crypt = new String("");
- byte[] byteArray = null;
- try {
- byteArray = clear.getBytes("UTF-16");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- if(byteArray !=null) crypt = Base64.encodeToString(byteArray, Base64.DEFAULT);
- return crypt;
- }
- _________________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement