How to write c++ program to transfer files to cellphone.

How do I write a c++ program to
transfer a text file to my
smartphone through a usb port? I can connect my
smartphone to my laptop. Is there
Any way to do it?
Last edited on
You just download the "android usb transfer" you now have a viewable storage interface, and you can access it through C++ if you have the absolute path to it.

On windows it will automatically download what you need for you.
Last edited on
There are two distinct avenues of approach, and your question doesn't seem to acknowledge them, so let me point these out.

Direct device connection

First, you could mean how to do what ADB does for Android. This is a "direct" connection between the OS and Android. The ADB "push" command is what you want, and it is a command line tool already built. iOS uses iTunes. Much of iOS is design to stop this from happening otherwise. Android is a little more open, but not by much. I assume we're not talking about rooted or jailbroken devices.

Internet transfer to an application

You could mean sending a text file over the Internet to a recipient as part of the way an application operates. This assumes you wrote the application receiving the text and the user installed it. This can work on both operating systems within the limits given to applications that write files to storage.

What that means

A direct connection differs on the two operating systems and conflicts generally with their security interests. Using TCP/IP as a connection between two C++ applications, one running on the phone, is common to both major platforms and is like any C++ code designed to send/receive data over sockets.

For Android this assumes you know how to build native libraries in C++ for Android application targets.

For iOS this assumes you can mix C++ with either Objective-C or Swift based projects.

Given suitable projects for both platforms which support C++ code, the objective might be met by using rather common TCP/IP data transfer support, for which there are many options. This is basically opening a connection, the sending and receiving packets and data.

The standard library of C++ offers Asio. There are older "sockets" support libraries as well.

The task is basically making a C++ program that can transfer data over the TCP/IP (which is then either WiFi locally, or the Internet at large), installing one on the phone and another on the PC.


I think I mean a direct connection through a usb port. I certainly don't mean wifi or internet.
So how do I write c++ program to send messages through usb port to smartphone.
Which smartphone? Android or iOS?
It is a phoenix lg
Not exactly what I asked, but that must be Android unless you're Japanese.

Your best bet is to use ADB (Android Device Bridge) at the command line. Use C++ to drive the command line using the "system" function of Windows (or *Nix for that matter).

Use the ADB push command (read on how to use ADB), and simply fashion the appropriate command line for a file to send.

At what I perceive to be your level of C++ study, you're not going to find much beyond that within your grasp. If you were going to dig deeper, you'd take the source code of ADB, decipher it, pull out what you need to use from it and build whatever you like. Some of us with lots of experience might actually choose that approach, but if this is just about pushing a few files - I'd use ADB command line.

That said, Android is Linux. The Linux operating system is underneath Android. If the phone is rooted and you want to use that as a requirement, you could connect to the device just like most Linux machines. If that's not familiar, then we're back at that same point I've made where this is probably something a year or so away from your current level of study.
Registered users can post here. Sign in or register to post.