hello sir in login page i am validating username and password from server database. if net is there means my application is working properly. if i disconnect internet means my application run means it show error application was not responding. how to eliminate this type of error
i try this code
if(name.equals("") || pass.equals(""))
{
Toast.makeText(Main.this, "Please Enter Username and Password", Toast.LENGTH_LONG).show();
}
else
{
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("server url/login.php");
// Add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim()));
nameValuePairs.add(new BasicNameValuePair("Password", pass.trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
response = httpclient.execute(httppost);
inputStream = response.getEntity().getContent();
data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data)) )
{
buffer.append(new String(data, 0, len));
}
inputStream.close();
}
catch (IOException e) {
System.out.println(e);
//alertDialog.cancel();
}
if(buffer.charAt(0)=='Y')
{
Intent intent=new Intent(getApplicationContext(),ManagerHandset.class);
startActivity(intent);
}
else
{
Toast.makeText(Main.this, "Invalid Username or password", Toast.LENGTH_LONG).show();
}
}
}
});
if i want disconnect my net means how to show alert net is not available
You can check your internet connection through this type of function:
Remember you have added following permissions in your Manifest file:
Edit
Hope this will work for you…