Payday Loan Payday Loan

Archive for the ‘Internet’ Category

Hi,
Today i want to show you how you can do background tasks and to update UI in the same time after the task is finished.
Let’s say you have a login method that return true if login succesfully and false if not succesfull.
Let’ s see the code:

//here we initialize a ProgressDialog to show while the task is done in background
ProgressDialog mProgressDialog;
		boolean result;
		public class SigninAsync extends AsyncTask<Void, Void, Boolean> {
			@Override
			protected void onPreExecute() {
				mProgressDialog = ProgressDialog.show(SigninPage.this,
						null, "Signing in...", true, false);
			}
 
			@Override 
			protected Boolean doInBackground(Void...voids) {
				result = doLogin();
	                         //observe the use of Boolean so that on PostExecute you can take some action based 
//on the returned result
				return result;
			}
 
			@Override
			protected void onPostExecute(Boolean result) {
				mProgressDialog.dismiss();
				if (result){
                                         //if result successfull go to next page
					Intent intent = new Intent(SigninPage.this, MainPage.class);
					startActivity(intent);
				} else {
				AlertDialog dialog =  new AlertDialog.Builder(SigninPage.this).create();
				dialog.setTitle("Login!");
				dialog.setMessage("Authentication failed! Please check your email and password!");
				dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",new DialogInterface.OnClickListener(){
 
					public void onClick(DialogInterface dialog, int wich) {
						// TODO Auto-generated method stub
						dialog.dismiss();
					}});dialog.show();
				}
 
			}
		}

Hope this helps you!

||||| 1 I Like It! |||||

Hi,
I want to show you how to parse JSON in Android:
This is an example of JSON string coming from server:

{
    "schools": [
        {
                "id": "s101",
                "name": "National School",
                "email": "nationalschool@gmail.com",
                "address": "Str.myStreet, nr.33",                
                "phone": {
                    "mobile": "+55 55515515551",
                    "home": "+55 55515515551",
                    "office": "+55 55515515551"
                }
        },
        {
                "id": "s102",
                "name": "Second Scool",
                "email": "secondschool@gmail.com",
                "address": "yourstreet,nr.22",
                "phone": {
                    "mobile": "+55 5555553333",
                    "home": "+55 5555553333",
                    "office": "+55 5555553333"
                }
          }
     ]
}

I will show you how to make parse JSON recieved after you POST login data to server.
the folowing method will do exactly this:

public boolean postData() {
		    HttpClient httpclient = new DefaultHttpClient();
		    HttpPost httppost = new HttpPost("http://yoursite.com/login.php");
 
		    try {
		        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);		        
		        nameValuePairs.add(new BasicNameValuePair("email", "example@mail.com"));
		        nameValuePairs.add(new BasicNameValuePair("password", "123456"));		        
				httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
 
 
		        HttpResponse response;
 
			response = httpclient.execute(httppost);
 
		        HttpEntity httpEntity = response.getEntity();
	            is = httpEntity.getContent();    
		        Log.v("", "Response from server: " + response.toString());
		    } catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();			
		    } catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
//Here we have the response from server and we convert it to a JSON Object		 
	            BufferedReader reader;
				try {
					reader = new BufferedReader(new InputStreamReader(
					        is, "iso-8859-1"), 8);
 
	            StringBuilder sb = new StringBuilder();
	            String line = null;
 
					while ((line = reader.readLine()) != null) {
					    sb.append(line + "\n");
					}
 
	            is.close();
 
	            json = sb.toString();
 
 
		    	try {
					jObj = new JSONObject(json);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
 
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();			
		        }
		  try {
				//as you observe we get the array called schools..look in example
//then we get the childs for this array..
			jsonArray = jObj.getJSONArray("schools");
			for (int i = 0; i < jsonArray.length();i++) {
				JSONObject c = jsonArray.getJSONObject(i);
				id = c.getString("id");
				Log.d("","VALIDD IS:"+id);
				name= c.getString("name");
                                email = c.getString("email");
 
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//Lets say that if you get id = 1 means that you are logged in and the data come to you for parsing so this
 //function will return true because the login is successfully done.
	    if (Integer.parseInt(id) == 1){
	    	return true;
	    }
	    else {
	    	return false;
	    }
 
		}

If you want you can call this method like this:

if(postData){
//go to screen when the Login is succesfull
}
else {
//show alert that the email and password do not match.
}

If there are any queries please comment and i will answer you. Thanks.

||||| 1 I Like It! |||||

Hi,
This is a simple way of sending a mail from your app. You will use Android default email client and you will send to the app your variables like this.

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"mymail@mail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT   , "Body");
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

Hope this helped you.

||||| 0 I Like It! |||||

Hi, this is the best method to find out if there is internet connection on device.
Most important thing is that you need the following permission added:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

The method is:

private boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager 
          = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null;
}
||||| 0 I Like It! |||||

Play a .pls file in Android.

Ok , I suppose most of you know that to listen to a radio station from Shoutcast you need to play a .pls file.
If you download the .pls file on your Android phone and you’ll try to play it you’ll notice that you can’t do that.
So, in this tutorial I’ll teach you how to play a .pls file in an Android application.

Like always, I made a short sample which you’ll be able to download .I’ll explain you step by step by adding comments in the Java code. In this project I created only a class and an XML file.

Ok. Here is the ListenToTheRadio.class :

public class ListenToTheRadio extends Activity{
 
MediaPlayer mp; //We declare the mediaplayer
Button bStart,bPause,bStop; //We declare the buttons we will use
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
 
mp = new MediaPlayer();
 
bStart = (Button) findViewById(R.id.bStart); //findviewbyid for this 3 buttons
bPause = (Button) findViewById(R.id.bPause);
bStop = (Button) findViewById(R.id.bStop);
 
bStart.setOnClickListener(new View.OnClickListener() { //Ok this is the most importat part, be focused !
 
public void onClick(View v) { //This happens when we click the Start button.
// TODO Auto-generated method stub
 
/* Ok, let me explain what this "if" does. The mediaplayer can be stopped or paused. If it is paused with
mp.start(); we can resume it but if it is stopped we need to setDataSource and prepare it again(to get data from the link).
So, I made as when we click the start button , it will unclickable but when you click pause or stop it will be clickable.
If this is foggy for you I think you will understand more as you read the code.
*/
if(bStop.isClickable()){
 
mp.start(); //Here we resume after we pressed the Pause button.
 
}else{
 
try {
mp.setDataSource("http://92.114.63.16:8100/"); //Here we set the source
//As you see, you need to enter the link to the shoutcast radio.
//DO NOT write /listen.pls also, write ONLY the link
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) { //This try and catch we need to put them because if we don't
//will have errors.
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mp.prepare(); //We prepare the mediaplayer to run.
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace(); //Another some boring try and catch clauses.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
mp.start(); //Here we DO NOT resume, we START the MediaPlayer.
 
//Here we set the clickable value for the 3 buttons
bStart.setClickable(false);
bPause.setClickable(true);
bStop.setClickable(true);
}
}
});
 
bPause.setOnClickListener(new View.OnClickListener() {
 
public void onClick(View v) {
// TODO Auto-generated method stub
mp.pause(); //We pause the MediaPlayer
 
//Start button will be clickable, as well as the Stop button but the Pause button will be unclickable
bStart.setClickable(true);
bPause.setClickable(false);
bStop.setClickable(true);
}
});
 
bStop.setOnClickListener(new View.OnClickListener() {
 
public void onClick(View v) {
// TODO Auto-generated method stub
mp.stop(); //Here we stop the MediaPlayer
 
//Another change for the buttons clickable's values.
bStop.setClickable(false);
bPause.setClickable(false);
bStart.setClickable(true);
}
});
 
bPause.setClickable(false);
bStop.setClickable(false); //At first we will be able to click only on the start Button
 
}
}

Here is the mylayout.xml file where we have the three buttons :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
 
    <Button
        android:id="@+id/bStart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start" />
 
    <Button
        android:id="@+id/bPause"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pause" />
 
    <Button
        android:id="@+id/bStop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Stop" />
 
</LinearLayout>

VERY IMPORTANT !
In your Manifest file please enter the Internet Permission :

<uses-permission android:name="android.permission.INTERNET"/>

You can download the entire project from here .

This is all for this tutorial. Thank you for reading and I hope you enjoyed it.

||||| 0 I Like It! |||||

What is an android tablet?

Hi,
Here i want to share with you some infos about the new technology: tablets with Android operating system.
These devices have same functionality like phones but with a bigger screen size. Also some tablets can have or not the telephony module.
There are 7 to 15 inch sizes tablets on which you can play much better then on phones and you can visit websites or read books in a great new way.
To see what are the most common facts you can do with a tablet, please look at the below statistics:

The average tablet user spends 90 minutes per day on their tablet. 88.3% of tablets are used on the road. 35% are used in the bathroom.
The average tablet user spends $34 on tablet apps.
By 2015 there will be 82.1 million tablet users in the United States.
The most common display size for a tablet is 10 inches.
54% of tablets owners are 34 and older.
80% of tablet users says that tablets have improved their work/life balance.
25% of tablet users are using printed books less.

Survey Says: People Love Their Tablets!

Here is a video with details about ASUS Transformer Pad Infinity:

You can visit TOP 15 Tablets in world here:
http://www.techradar.com/news/mobile-computing/tablets/15-best-android-tablets-in-the-world-905504

||||| 0 I Like It! |||||

How to parse from a csv file on Android

I will show you how to parse lines from a csv file that is situated on a server.

String[][] content=new String[50][50];
 try {
			            	        HttpClient httpClient = new DefaultHttpClient();
			            	        HttpContext localContext = new BasicHttpContext();
 
 
			            	        HttpGet httpGet = new HttpGet("http://yourhost.com/yourfile.csv");
 
			            				 response = httpClient.execute(httpGet, localContext);
			            			} catch (ClientProtocolException e) {
			            				// TODO Auto-generated catch block
			            				e.printStackTrace();
			            			} catch (IOException e) {
			            				// TODO Auto-generated catch block
			            				e.printStackTrace();
			            			}
 
			            		try {
			            			is = new InputStreamReader(response.getEntity().getContent());
			            		} catch (IllegalStateException e1) {
			            			// TODO Auto-generated catch block
			            			e1.printStackTrace();
			            		} catch (IOException e1) {
			            			// TODO Auto-generated catch block
			            			e1.printStackTrace();
			            		}
 
 
			            	         reader = new BufferedReader(is);
 
			            	         try {
			            	         	int row = 0;
			            	         	int col = 0;
			            	         	String line = "";
 
			            	 			//read comma separated file line by line
			            	 			while((line = reader.readLine()) != null)
			            	 			{
			            	 				StringTokenizer st = new StringTokenizer(line,",");
			            	 				while (st.hasMoreTokens())
			            	 				{
			            	 					//get next token and store it in the array
			            	 					content[row][col] = st.nextToken();
			            	 					col++;
			            	 				}
			            	 				col=0;
			            	 				row++;
			            	 			} row--; 
 
			            for(int i=0;i<=row;i++)
			            {            	
Toast.makeText(Main.this,content[i][0],Toast.LENGTH_LONG).show();
//here we display some values, but actually you can make what you want with values from this matrix
//
	}
 
 
 
 
 
			            	         }
			            	         catch (IOException ex) {
			            	             // handle exception
			            	         }
			            	         finally {
			            	             try {
			            	                 is.close();
			            	             }
			            	             catch (IOException e) {
			            	                 // handle exception
			            	             }      
 
			            	         }
||||| 0 I Like It! |||||

How to login with POST in Android

I will show you how to call a php file from a server. You will send parameters, and will get an answer from the php file.
Let’s assume we have a login form.
So, we need to send username and password parameters to server.
Server will respond with ok, or fail if parameters sent are correct.

HttpClient httpclient = new DefaultHttpClient();
		    HttpPost httppost = new HttpPost("http://androidgenuine.com/test_file.php");//here is the 
host where the php file is.
 
		    try {	    		
 
		        // Add your data
		        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
		        nameValuePairs.add(new BasicNameValuePair("username","John"));
		        nameValuePairs.add(new BasicNameValuePair("password", " "));
		        nameValuePairs.add(new BasicNameValuePair("action", "validate_password"));
 
		        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
 
		        // Execute HTTP Post Request
		        HttpResponse response = httpclient.execute(httppost);
		        String responseAsText = EntityUtils.toString(response.getEntity());
		        Log.d("", responseAsText+"dadadad###");
		if(responseAsText .contentEquals("ok")){
//make what you want if login ok
}
else{//make what you want if login fails
}
  } catch (ClientProtocolException e) {
		        // TODO Auto-generated catch block
		    } catch (IOException e) {
		        // TODO Auto-generated catch block
		     }

You need permissions to use this:android.persmissions.INTERNET

||||| 0 I Like It! |||||

I have found this software that seems to be a very helpfull tool in developing any kind of apps. Android, iPhone, or Windows apps you can do all of that without knowledge of programming with this very helpfull tool.
There are lots of tutorials and projects ready-made just to show you how easy you can develop Android apps, and publish them.

Welcome to Appcelerator from Appcelerator Video Channel on Vimeo.

||||| 0 I Like It! |||||

How to make a WebView on Android

To make a webview on Android is relative easy, you need some settings enabled and very important to set an attribute in the AndroidManifest file. You will need webview.xml which looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content" android:layout_height="fill_parent">
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="horizontal">
<WebView android:layout_marginTop="60sp" android:id="@+id/webview01" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
 
</ScrollView>
</LinearLayout>

The code looks like this:

package com.webview;
 
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
 
public class Main extends Activity {
	WebView webview1;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);
 
        webview1 = (WebView)findViewById(R.id.webview01);
 
        webview1.getSettings().setJavaScriptEnabled(true); 
        webview1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
 
        webview1.getSettings().setBuiltInZoomControls(true);
	    webview1.setInitialScale(50);
        webview1.loadUrl("http://www.mywebsite.com/"); 
 
    }}

You need also to include in your Manifest file the following code that will be put
immediately after

</application>

tag :

<uses-permission android:name="android.permission.INTERNET" />

I hope this can help you to implement a webview. You can set the size of the window modifying the attributes layout_width and layout_height to custom sizes like 100 dip or 200 dip etc..

||||| 0 I Like It! |||||

Search

Popular

Sponsors