Android game developers have experience of developing and successfully distributing Android games. With its stunning visual design, mind-bending sci-fi soundtrack and effortless game play rules, has made Android the most immersive, engaging game developer. Thanks a lot.Inbound Marketing
Hi, Thanks for posting this great example. I'm trying to develop an app which needs to transfer a txt file from my android to a remote computer. I tried this example (copied and pasted) and it runs (Android app and Java server) but it does not transfer the file. It creates the file and it shows the message: Server started. Listening to the port 4444Receiving...But it doesn't receive anything. I'm not sure if there has to be any kind of permission for accessing the file on the Android phone. Thanks for your help.Alberto.
Alberto,No,It doesn't need any file accessing permission. If the sever says "Receiving..." it has accepted the client connection. Seems like you are trying to send a large file. For a large file it will take some time.
Hi Lakjeewa,I deeply appreciate your answer. Yes, on the server side says "Receiving" but it does not receive anything. It does create the file but after some time (5Minutes) it is still empty. I tried with a JPEG file (5MB) and it did not work, then I tried with a txt file (less 1KB) but it did not work either. Where should I locate the file on the phone?The path where the file is:/mnt/sdcard/DCIM/100MEDIA/file.txt or file.jpegDoes it work with the android emulator? because I tried it with both, emulator and phone. Thanks for your help and time Lakjeewa,Alberto.
Anyway it doesn't take 5 minutes for 5MB file. When the sever says "Receiving...", it just accept the client connection. Actually, following lines of code after line 43 read the file. I think your client (Android emulator) doesn't send the file.For your case, don't forget to change the file path in line 47 of client code to "/mnt/sdcard/DCIM/100MEDIA/file.txt". This code is specially for Android emulator. If you are going to try this with a phone, you will need more configurations in both client and sever side.
Hi,Thanks!. Yes, I did change the path and put the specific file's path. But it still does not work. What path should I use for the emulator and which one for the phone? Does it matter? Thanks again!.
It doesn't matter the path. The thing is if you try for phone, you should have a network connection with the sever (wired or wire-less). So, making a network is another task.
Thank's a lot but I have a doubtwhat If I wanna see the file that I send to the server.java, what should I do?
i get a android.os.NetworkOnMainThreadException T.Thelp
This comment has been removed by the author.
I am trying to send .txt file and its giving me the output but when I am sending .doc file or any image file its not giving any output...I am running this code in my Android device...
David,you can go to the place where you save the file in the sever and you can just open the file using relevant program. In this post, the file is jpg file and it can be open using any image viewer.
Anil,In this post im using a jpg image file and it works fine. Hope you have put the file name in the sever side with correct extension. (eg: .jpg , .txt , .doc)
I am running my app on android device which has the latest SDK support such as 4.0. But when I press button then my app stops and do not give any output. I want to ask that this app runs on upper versions or it runs only on lower versions...???
This application is programmed only for emulator which is working in local host environment. If you want to run this application in a device you should build a connection between the server and the device. It is an additional task which needs more effort. You can build a connection via web or Bluetooth technology.
Thanks for your reply always...I am developing an application in which from my mobile I am sending files to the WiFi printer by IP address and port number, which are .txt, .png, .jpg, .doc. They should be printed from the printer. I have tried your code but it is giving me output for .txt file only. What changes are required to get output of all type of files??? Please help me...Its my project...Once again thank you...
I'm getting this error, "emulator-5554 disconnected! Cancelling 'com.example.filetransfertoserver.SimpleClientActivity activity launch'!" any help?Thanks!
after debugging I found why it stands as receving an never finishesupdate this variable with your file size.!!! otherwise it wont finishprivate static int filesize = 10000000; // filesize temporary hardcoded
Hai, Really awesome blog.I need a help how to send live recorded video to remote server from our android smartphone.kindly help me.
I am getting Error : Please advicedalvik.system.basedexclassloader.findclass classnotfoundexception
As I followed same step which u have been explained in above
Can you upload code for sending files or even text to remote (publicly available) machine. So basically the app send data from smartphone to server (one way communication is fine for now).
Thanks a lot for the post , it is really helpful. You saved my day
@Alaa smarnehcan you please mail the .apk to me...firstname.lastname@example.org
Very nice Blog..I have one simple question...how do we check this code..android code in android phone and server code in laptop?? silly question but will be very helpful for me...Thank you
Hi all ,dear lakjeewa do we use same for video .ogg etc.
hey Madhuranga Lakjeewa ..excellent work..... i m trying to run this code but i m getting few errors ...... can u plz provide download link for this code ...my mail id is email@example.com
i implement it with two emulator , and i have no errorbut it's just print receiving !and i didn't receive anything :S
firstname.lastname@example.org you email me the source code plz
You kep saying for this code to work on phones we need to establish connection. Can you please tell me how t establish connection between an android device and a laptop both wid their own net connection (not sharing the same ip).Thank you in advance.
why IP 10.0.2.2 I change Localhost no run?
Is there a way to not have the file hard coded in and have the app locate it in the phone's directory?
Where does the server run? In the emulator?Sorry if my question is lame..I'm a newbie
Hi...i was trying to execute the above code and noticed that the apk gets installed (\SimpleClient\bin\SimpleClient.apk installed on device) but does not appear in the emulator...Also can you please let me know how to establish a connection to transfer a file from pc to android as i am new to android.
i suppose im lucky to have found this! I hope you will be adding more in the future...facetime
really good piece of information, I had come to know about your site from my friend shubodh, kolkatta,i have read atleast nine posts of yours by now, and let me tell you, your site gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanks a lot once again, Regards, obiee training in hyderabad
Buddy, ... suppose i received an file from server , and i want it to preview in my client app , and for that purpose i need to call the "open with" facility of android to open and preview that file in that client app ... for ex: i recieved an image or a text file from server and i want to preview it in the app , so on click of preview button that should show "open with" dialog box and give the options of all the file viewer present in that device for that particular file , i.e. it should give me picasa or gallery option for an image file ........so can u give me any idea ... how to achieve this kind of things ..m strucked in my project right now ....thnx in advance ...
Hi guys,Do you have any idea about to fetch android system file (ex: log) by using server programming??? Make sure android system must not aware of fetching... Don't think it is for illegal purpose, i am a researcher need to work on some data analysis
Thank you very much for this tutorial. However I got a 'network on main thread exception' but solved it using AsyncTask :)
Great to see someone from SL. :)Yeah Lakshitha, Above tutorial is based on Android API Level 10. But API Level 11 introduced AsyncTask implementation for network communication. Therefore this tutorial is now deprecated. As you found AsyncTask is the solution and then it works. :)
Hello my friend... first as sending messages and files after the same sockethow achieve
Do you want to send the message and the file at the same time?