简体   繁体   English

可以将文件从 Windows 应用程序直接写入 Android SD 卡吗?

[英]Possible to write files from Windows application directly to Android SD card?

I'm looking for a way to write a file from a Windows application to an Android device SD card over a USB connection.我正在寻找一种通过 USB 连接将文件从 Windows 应用程序写入 Android 设备 SD 卡的方法。 To do this, I will need to obtain the drive letter of the SD card, and it's mount point.为此,我需要获取 SD 卡的驱动器号,以及它的挂载点。 My Windows application is written in C++, so I'm most hoping for a solution in C++.我的 Windows 应用程序是用 C++ 编写的,所以我最希望在 C++ 中找到解决方案。 If not possible, perhaps there is a Java solution which can then be placed in a C++ wrapper to be called by my application's code.如果不可能,也许有一个 Java 解决方案,然后可以将其放在 C++ 包装器中,由我的应用程序代码调用。

I've searched around and come up with a few ideas but nothing seems to work yet.我四处搜索并提出了一些想法,但似乎还没有任何效果。 First, I came across Google's documentation on a method,Environment.getExternalStorageDirectory(), but my assumption is that since this is part of the Android SDK, it is only usable from an application residing on an Android device.首先,我遇到了 Google 关于方法的文档,Environment.getExternalStorageDirectory(),但我的假设是,由于这是 Android SDK 的一部分,因此它只能从驻留在 ZE84684E30B9AB9387CDB4684E30B9AB387CDB4684E30B938066 上的应用程序中使用。 Secondly, I came across some functions in Windows' native API (WinBase.h primarily), which provides a way of locating all drives and their corresponding letters, but even if I can get this information, I don't know how to determine which of these is the connected Android device's SD card.其次,我在Windows原生的API(主要是WinBase.h)中遇到了一些功能,它提供了一种定位所有驱动器及其对应字母的方法,但即使我能得到这些信息,我也不知道如何确定哪个其中是连接的 Android 设备的 SD 卡。

Any help is appreciated!任何帮助表示赞赏!

I'm not a windows application expert but if you can use system calls in your C++ program to call adb.exe, then you can execute adb commands directly to the device.我不是 windows 应用程序专家,但如果您可以在 C++ 程序中使用系统调用来调用 adb.exe,那么您可以直接对设备执行 adb 命令。

For example if you can execute "adb.exe devices" you can get a list of all android devices currently attached to the computer.例如,如果您可以执行“adb.exe devices”,您可以获得当前连接到计算机的所有 android 设备的列表。 From there, you can use any adb commands to push files onto the device.从那里,您可以使用任何 adb 命令将文件推送到设备上。

More information on the adb commands here: ADB wiki有关 adb 命令的更多信息: ADB wiki

What you're looking for is probably doing an adb devices in combination with adb push <your file> /sdcard/<file on sdcard>您正在寻找的可能是adb devicesadb push <your file> /sdcard/<file on sdcard>结合使用

Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM