Feb 7, 2012

Solve the “Debug certificate expired on” error message , Android Error: Error generating final archive: Debug certificate expired on

long ago i tried to run my running suddenly it showed error , but i didn't find any error in my source code in java & XML also ,


The problem comes from the fact that Android required the applications to be signed even in the debug mode. So it uses a keystore file called debug.keystore to providde keys for signing applications in debug mode. This key store file has a validity period by default 365 days from its creation date.


The First Solution:


Navigate to the .android folder in your home directory “~/.android” (Linux,Mac OS)
or c:\Documents and Settings\[User Name]\.android in windows XP
or C:\Users\.android in windows Vista or Windows 7, and delete debug.keystore file.


how to find .android folder in Linux ( UBuntu ) :

click on places menu under select home folder under then click on View Menu under click on showhiddenfiles (ctrl+h) , then u can find out .Android file


Then go to eclipse clean the project, this will create a new debug.keystore file with
default validity period 365 days.

The Second Solution:


Create a new default.keystore file with custom validity period (say 1000 days).
Navigate to the .android folder.
Delete the old default.keystore file.
We will use JDK Keytool.exe to generate the new key file. It is found in C:\Program Files\Java\jre6\bin in windows or inside the Java\jre6\bin folder in Mac OS or Linux.
Open the terminal app in Mac OS or Linux or the command prompt and navigate to keytool.exe directory.
Run the following command:
keytool -genkey -keypass android -keystore debug.keystore -alias androiddebugkey -storepass android -validity 1000 -dname “CN=Android Debug,O=Android,C=US”
This will generate a new default.keystore file with validity period 1000 days.
Copy the generated file to the .android folder, go to eclipse and clean projects and it should work.
The above command has the following options:
genkey: generates a key pair.
keystore : the name of the key store file.
alias : an alias for the key store. If the alias name is more than 8 characters the first 8 only are used.
storepass : the password for the key.
validity : the validity period for the key in days.
dname : A Distinguished Name that describes who created the key. The value is used as the issuer and subject fields in the self-signed certificate.

Dec 7, 2011

How to send Post data to PHP server in android

public boolean PostData() {
try {
// creating default Client
HttpClient mClient = new DefaultHttpClient();
// Connect URL
StringBuilder sb=new StringBuilder("URL_OF_WEB_SERVER");
// Establishing post connection to Specified URL
HttpPost mpost = new HttpPost(sb.toString());
// NameValuePair : A simple class encapsulating an attribute/value pair.
// List Size is 8 atributes
List nameValuepairs = new ArrayList(8);
// adding attributes to List
nameValuepairs.add(new BasicNameValuePair(name1,val1));
nameValuepairs.add(new BasicNameValuePair(name2,val2));
nameValuepairs.add(new BasicNameValuePair(name3,val3));
nameValuepairs.add(new BasicNameValuePair(name3,val3));
nameValuepairs.add(new BasicNameValuePair(name4,val4);
nameValuepairs.add(new BasicNameValuePair(name5,val5));
nameValuepairs.add(new BasicNameValuePair(name6,val6);
nameValuepairs.add(new BasicNameValuePair(name7,val7));
// UrlEncodedFormEntity :An entity composed of a list of url-encoded pairs. This is typically
// useful while sending an HTTP POST request.
mpost.setEntity(new UrlEncodedFormEntity(nameValuepairs));
// excute request and get response
HttpResponse responce = mClient.execute(mpost);
// get response content
HttpEntity entity = responce.getEntity();
// convert stream to String
BufferedReader buf = new BufferedReader(new InputStreamReader(entity.getContent()));
StringBuilder sb1 = new StringBuilder();
String line = null;
while ((line = buf.readLine()) != null) {
sb1.append(line+"\n");
}
Toast.makeText(getApplicationContext(), sb1.toString()+"",1).show();
tv.setText(sb1.toString());
isPosted = true;
} catch (UnsupportedEncodingException e) {
Log.w(" error ", e.toString());
} catch (Exception e) {
Log.w(" error ", e.toString());
}
return isPosted;
}