Posts

Showing posts from 2014

Create Custom Dialog in Android

Image
Creating a custom dialog by using the method setContentView(viewtype). To use this function you have to create a reference variable for Dialog class object as i have done below Dialog dialog=new Dialog(Context); LayoutInflater inflater = LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v1=inflater.inflate(R.layout.yourlayout, null); //perform operation on elements in Layout dialog.setContentView(v1); dialog.show(); //For getting the elements in the layout you have to use the findViewById on the View v1. //Just like this and perform whatever function you have to perform on click of the button. So isn't it simple. Button button=v1.findViewById(R.id.buttonid); Getting IP address of the android device visit this  link

Creating Database at Server Using WampServer for Android

Image
Step 1 : You have to download the wamp server and install it in your system.The download link for wamp server is  http://www.wampserver.com/ . After installing the wamp server run it you will find a green icon at your notification area. If its not green then something is went wrong while installing the server.                                                   Step 2 : Click on the green icon. Step 3 : Click on phpMyadmin. A link will be opened in your default browser. Step 4 : Under the text Create new database there is a text field enter the name of the database and click on create. A database will be created and will be show in the left side of the panel select your defined database from there . This is how a database is created in wamp server for android.How to use this will be later discussed on.

Server Client Communication in android Part-II

Image
Server Client Communication Now lets move on to the coding part of the server client communication in android. As a wrote in my previous blog about the  brief introduction of the server client concept used in android .Now hows its done lets view it Firstly u need a url where you server file resides for example localhost/myapp/index.php  or 192.165.17.1/myapp/index.php String url="where server file reside";             HttpClient httpclient = new DefaultHttpClient( );             HttpPost httppost = new HttpPost(url);             String done=null;             try {                  //created a arraylist of NameValuePair it is class encapsulating a name/value pair.                 // For more refer                                  //  https://hc.apache.org/httpclient-.x/apidocs/org/apache/commons/httpclient/NameValuePair.html                 ArrayList< NameValuePair > nameValuePairs = new ArrayList<NameValuePair>(1);                 nameValuePairs

Server Client Communication in android Part-I

Image
Server Client in Android is an important concept to learn its because  most application that has been developed in android is not standalone so they are totally dependent on the internet connection. So to communicate the application with the server you have to use the server side programming languages like php , jsp ,etc. So the Client side the android whereas the Server side will be the server side programs. The flow of information in the network is basically done by the HTTP request and android has its inbuilt classes for that purpose. Which the server catches by the method of the post and get methods .For example if we passed a string name with value "android" . So in server side the retrieval of  the name value is done by I am using php there its done like it $name=$_POST["name"]; If you echo $name you will see that the android is being printed. There different ways to send the information and you will be need extra library if the level of information

How to Show Error Message in EditText

Image
To showing a error message in the edit text is really simple actually.To done this you have to first create a reference variable in android as indicated downwards EditText editrefer= findViewById(R.id.edittextname); Then you have to call an function i.e. setError() function. It accepts only one parameters that is of the string type setError(""); The string will be the message you want to display like i have create a string as String errormsg = new String("Enter 10 digit Number"); setError(errormsg); To apply it on edittext you have to call this function on the edit text variable i.e  editrefer  editrefer.setError(errormsg);

Define Global Variable in Android

Image
When we talk about global variable in java its not that the technique java has for that you have to make a single instance of a class. How its done in android? For this you have to create a Class named is as GlobalVariable.java,then extends the class with Application so that we can create only one instance of the class. import android.app.Application; public class GlobalVariable extends Application { //add this variable declaration: public static String global_variable;                              //Generate getter and setter                 public static String getgobal() { return global_variable; } public static void setglobal(String global_variable) { GlobalVariable.global_variable = global_variable; }                 private static GlobalVariable singleton; public static GlobalVariable getSingleton() { return singleton; } public static void setSingleton(GlobalVariable singleton) { GlobalVariable.singleton = singleton; }

Upload Image to MySQL blob through Android

Image
For uploading an image to the MySQL database is really quite simple just you have to follow these simple code snippet. Android Case Get an image using the android you can do this by using startActivityForResult(intent,requestcode) Use this code onClick Method of the Button   Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);   photoPickerIntent.setType("image/*");   startActivityForResult(photoPickerIntent, 100); Then override this below method button in the activity         @Override protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent);   if(imageReturnedIntent!=null)   {    if(requestCode == 100){            Uri selectedImage = imageReturnedIntent.getData();            InputStream imageStream = null; try { imageStream = getContentResolver().openInputStream(selectedImage); } catch (FileNotFoundException e) {