Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Wednesday, January 7, 2015

Android Client-Server Chat Application

This is a simple Android chat application which communicate with a Java server program. This tutorial will help you to understand socket programming in Android which sends information both ways.
To run this application, first execute the server program. You can run this application in your PC.

Then execute the client program. You can use your Android emulator or your Android device. If you are using Android emulator you can use IP address 10.0.2.2 to connect your sever which is running in the same computer. But if you are using an Android device you may have to change the IP address in the client app code according to your network configuration.
Once you execute the client app, the chat window will be opened in the server program. Type the message on the chat box and press "Send" button. The message will be appeared in the other end.

      
Android Chat App
 
Server Program





                                                         









                                                                                   
Following are the source codes of the main components of both programs.

Android Chat Application


Server Program


Following are the both Android client and Java server complete projects. You can clone or download them as zips from Git-Hub.

Git-Hub HTTPS clone URL: https://github.com/lakjcomspace/AndroidChatClientServer.git
Git-Hub Repository URL: https://github.com/lakjcomspace/AndroidChatClientServer
Download as a Zip: https://github.com/lakjcomspace/AndroidChatClientServer/archive/master.zip

You can run the projects by importing them to the IDE. Or just create you own project and copy and paste above source files.

Sunday, October 5, 2014

Android USB Debugging in Huawei Tab

If you are writing android applications you may definitely do USB debugging. In case you don't know the the term, USB debugging (On-device Developer Option) is using a real android device to debug your android application by connecting it through USB port.
In this blog post i am going to explain you how to use your Huawei android tab for USB debugging. I have tested this with a  "Huawei Mediapad 7 Lite".


On Android developer guide it has been mentioned that we have to install USB driver software for this, but you may not able to find the relevant driver software for Huawei.
In our case, more interesting thing is you don't want to bother for finding driver software. Lets do this step by step.

1. Declare your application as "debuggable" in your Android Manifest.
If you are using Eclipse, this may have been automatically declared. Otherwise go to AndroidManifest.xml and add android:debuggable="true" to the <application> element.

2. Enable USB debugging on your device.
Go to Settings > Developer options. (For  Android 3.2 or older Settings > Applications > Development)
Developer options is hidden by default on Android 4.2 and newer. To un-hide it, go to Settings > About phone and tap Build number seven times. Then go back to the previous screen to find Developer options.

3. Plug your device to your PC using the USB cable.
The device will notice you that you have connected the dive to the PC.

4. Click on the notification bar of the device (Where are time/battery/signal information are). On the pop-up menu you may see the USB connection type. Probably it would be "Connected as a media device".
If you have properly activated the USB debugging mode, it may also be shown as "USB debugging connected".

5. Click the "Connected as a media device" option (Or any other "Touch for other USB option" menu item). You may be navigated to a "Connect As" menu in the Settings > Storage menu.
There select the "HiSuite" option. You will be notified the action. Your device UI will change to HiSuite UI.

6. Now move to your PC. Navigate to the device from the PC file browser (If you are using Windows OS go to Computer > HiSuite in removable storage category).

7. There you may find the HiSuiteSetup.exe file and double click and install the software.

8. Once it is installed, you are done!

9. Remove the device and plug the device again. Make sure you have connected the device as "Connected to HiSuite". The HiSuite software will automatically start-up on your PC.

You can verify that your device is properly connected  by executing adb devices from your Android SDK platform-tools/ directory.

Following is the UI of the HiSuite PC software. Using this software you can do many things related to your Huawei Android device (Not only USB debugging).


Saturday, August 23, 2014

Share Laptop Internet Connection With Android Device


Without using any software you can simply crate a wifi hotspot in Windows.

1. Open command prompt with administrator privileges. (Right click -> Run as administrator).

2. Enter following command to create the connection.
netsh wlan set hostednetwork mode=allow ssid=MyWifiName key=myPassword

Here you can give any values for 'ssid' and 'key'. ssid will be you wifi connection name and key will be the password.

3. Enter following command to start the network.
netsh wlan start hostednetwork

Make sure you have turn on wifi on your laptop. Otherwise you will be getting a message like following.
The hosted network couldn't be started.
A device attached to the system is not functioning.

When everything is properly configured, your command prompt would look like following.



4. Now open the "Network and Sharing Center" (Click internet connectivity icon on the task bar and open Network and Sharing Center or Go to control panel and click network and internet related options).
Click the "Change adapter setting" option in right hand-side of the window.
There you will see all your network connections also with our newly created network connection "MyWifiName".

5. This step is very impotent. Right click on you current internet connection icon (not on your MyWifiName icon). Click on the "Sharing" tab in the window you are getting. There tick the option "Allow other network users to connect through this computer's internet connection".
Then select your newly created MyWifiName connection as the "Home networking connection" in the drop down. There you won't have the name MyWifiName but the title name related to that connection. You can get that title name from Change adapter setting window. Click ok button.

6. Now you are done!

Turn on your Android or any device and connect to MyWifiName wifi hotspot using the password myPassword.

To turn off the network you created, enter the following command

netsh wlan stop hostednetwork


Monday, May 5, 2014

Simple Android Client-Server Application

This is an android application which sends a text message to a server. When you press the send button, the application sends the message in the text field to the server program. Here the program been written so that the client runs on the Android emulator and the server runs on the local host. IP address 10.0.2.2  can be used to connect to the local host with Android. Server program is continuously listening to the port 4444. When an incoming message arrived, server read it and show it on the standard output.
This tutorial is based on Android 4.4 (API Level 19 - KITKAT) version.



Following are the source codes of main components.

Android Text Client Application




Java Sever Program



Following are the both Android client and Java server complete projects. You can clone or download them as zips from Git-Hub.

Git-Hub HTTPS clone URL: https://github.com/lakjcomspace/AndroidTextClientServer.git
Git-Hub Repository URL: https://github.com/lakjcomspace/AndroidTextClientServer
Download as a Zip: https://github.com/lakjcomspace/AndroidTextClientServer/archive/master.zip
You can run the projects by importing them to the IDE. Or just create you own project and copy and paste above source files.

Friday, March 30, 2012

Android Application to Send a File to Remote Server

This simple Android application sends a file to a remote server. In this example code server runs on local host. When the Send button is clicked the file is sent to the server.

Android Client Application
Server Application

Thursday, March 29, 2012

Simple Client-Server Application for Android


Note: Here is the updated tutorial of the following tutorial for the latest Android version:
http://lakjeewa.blogspot.com/2014/05/simple-android-client-server-application.html 

Following tutorial is based on Android 2.3 (API Level 10). It is not compatible with later versions since API Level 11 introduced AsyncTask implementation for network communication. Refer the above link instead for working solution. 

This application is a simple client-server application which has a Android mobile client and a Java server which is run on a machine. In this example, client is run on the Android emulator and the server is run on the local host. In Android 10.0.2.2 is the IP address for local host. This application allow to type a text message on a text field and when the Send button is press the message is sent to the server. Server continuously listen to the port. When there is a incoming message server read it and show it on the standard output.



Client Side Application



Server Side Application