Android 如何使用 adb 命令在没有 SD 卡的设备上推送文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20834241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:33:10  来源:igfitidea点击:

how to use adb command to push a file on device without sd card

androidadb

提问by Nikhil Kumar

How to push a file from computer to a android device having no SD Card in it. I tried:

如何将文件从计算机推送到没有 SD 卡的安卓设备。我试过:

C:\anand>adb push anand.jpg /data/local
3399 KB/s (111387 bytes in 0.032s)

C:\anand>adb push anand.jpg /data/opt
3199 KB/s (111387 bytes in 0.034s)

C:\anand>adb push anand.jpg /data/tmp
3884 KB/s (111387 bytes in 0.028s)

above commands to move a file anand.jpgto device but I didn't get this jpgfile in the device. I didn't get any success result on cmd prompt, I only got:

以上命令将文件移动anand.jpg到设备,但我没有jpg在设备中获取此文件。我在 cmd 提示符下没有得到任何成功结果,我只得到:

3399 KB/s (111387 bytes in 0.032s).

回答by Hardik Trivedi

From Ubuntu Terminal, below works for me.

从 Ubuntu 终端,下面对我有用。

./adb push '/home/hardik.trivedi/Downloads/one.jpg' '/data/local/'

回答by vincsilver

I did it using this command:

我是用这个命令做到的:

syntax: adb push filename.extension /sdcard/0/

句法: adb push filename.extension /sdcard/0/

example: adb push UPDATE-SuperSU-v2.01.zip /sdcard/0/

例子: adb push UPDATE-SuperSU-v2.01.zip /sdcard/0/

回答by SML

Follow these steps :

按着这些次序 :

go to Android Sdk then 'platform-tools' path on your Terminal or Console

转到 Android Sdk,然后转到终端或控制台上的“平台工具”路径

(on mac, default path is : /Users/USERNAME/Library/Android/sdk/platform-tools)

(在 mac 上,默认路径是:/Users/USERNAME/Library/Android/sdk/platform-tools)

To check the SDCards(External and Internal) installed on your device fire these commands :

要检查设备上安装的 SDCards(外部和内部),请使用以下命令:

  • 1) ./adb shell(hit return/enter)
  • 2) cd-(hit return/enter)
  • 1) ./adb shell(点击回车/回车)
  • 2) cd-(点击回车/回车)

now you will see the list of Directories and files from your android device there you may find /sdcard as well as /storage

现在,您将看到 Android 设备中的目录和文件列表,您可能会在其中找到 /sdcard 和 /storage

  • 3) cd /storage(hit return/enter)
  • 4) ls(hit return/enter)
  • 3) cd /storage(点击回车/回车)
  • 4) ls(点击回车/回车)

you may see sdcard0 (generally sdcard0 is internal storage) and sdcard1 (if External SDCard is present)

您可能会看到 sdcard0(通常 sdcard0 是内部存储)和 sdcard1(如果存在外部 SDCard)

  • 5) exit(hit return/enter)
  • 5)退出(点击返回/进入)

to come out of adb shell

从 adb shell 中出来

  • 6) ./adb push '/Users/SML/Documents/filename.zip' /storage/sdcard0/path_to_store/(hit return/enter)
  • 6) ./adb push '/Users/SML/Documents/filename.zip' /storage/sdcard0/path_to_store/(点击返回/输入)

to copy file

复制文件

回答by Jonas Borggren

Sometimes you need the extension,

有时你需要扩展,

adb push file.zip /sdcard/file.zip

adb push file.zip /sdcard/file.zip

回答by Rocky Chen

run below command firstly

首先运行下面的命令

adb root
adb remount

Then execute what you input previously

然后执行你之前输入的内容

C:\anand>adb push anand.jpg /data/local
C:\anand>adb push anand.jpg /data/opt
C:\anand>adb push anand.jpg /data/tmp

回答by Maik

I've got a Nexus 4, that is without external storage. However Android thinks to have one because it mount a separated partition called "storage", mounted in "/storage/emulated/legacy", so try pushing there: adb push anand.jpg /storage/emulated/legacy

我有一个没有外部存储的 Nexus 4。然而,Android 认为有一个,因为它挂载了一个名为“storage”的独立分区,挂载在“/storage/emulated/legacy”中,所以尝试推到那里:adb push anand.jpg /storage/emulated/legacy

回答by Alex

My solution (example with a random mp4 video file):

我的解决方案(以随机 mp4 视频文件为例):

  1. Set a file to device:

    adb push /home/myuser/myVideoFile.mp4 /storage/emulated/legacy/
    
  2. Get a file from device:

    adb pull /storage/emulated/legacy/myVideoFile.mp4 
    
  1. 设置文件到设备:

    adb push /home/myuser/myVideoFile.mp4 /storage/emulated/legacy/
    
  2. 从设备获取文件:

    adb pull /storage/emulated/legacy/myVideoFile.mp4 
    

For retrieve the path in the code:

检索代码中的路径:

String myFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myVideoFile.mp4";

This is all. This solution doesn't give permission problems and it works fine.

这就是全部。此解决方案不会出现权限问题,并且运行良好。

Last point: I wanted to change the video metadata information. If you want to write into your device you should change the permission in the AndroidManifest.xml. Add this line:

最后一点:我想更改视频元数据信息。如果您想写入您的设备,您应该更改AndroidManifest.xml. 添加这一行:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

回答by M. Usman Khan

As there are different paths for different versions. Here is a generic solution:

因为不同的版本有不同的路径。这是一个通用的解决方案:

Find the path...

找到路径...

  1. Enter adb shellin command line.
  2. Then lsand Enter.
  1. adb shell在命令行中输入。
  2. 然后ls输入。

Now you'll see the files and directories of Android device. Now with combination of lsand cd dirNamefind the path to the Internal or External storage.

现在您将看到 Android 设备的文件和目录。现在结合lscd dirName找到内部或外部存储的路径。

In the root directory, the directories names will be like mnt, sdcard, emulator0,etc

在根目录中,目录名称将类似于mnt, sdcard, emulator0,etc

Example: adb push file.txt mnt/sdcard/myDir/Projects/

例子: adb push file.txt mnt/sdcard/myDir/Projects/

回答by Naitik Soni

Try this to push in Internal storage.

试试这个来推入内部存储。

adb push my-file.apk ./storage/emulated/0/

adb push my-file.apk ./storage/emulated/0/

Works in One plus device, without SD card.

适用于一加设备,无需 SD 卡。

回答by solver

Certain versions of android do not fire proper tasks for updating the state of file system. You could trigger an explicit intent for updating the status of the file system. (I just tested after being in the same OP's situation)

某些版本的 android 不会触发适当的任务来更新文件系统的状态。您可以触发更新文件系统状态的显式意图。(我刚刚在同一个 OP 的情况下进行了测试)

adb shell am broadcast -a android.intent.action.MEDIA_MOUNTED -d file:///

(You could pass a specific filepath instead of file:///like file:///sdcard)

(您可以传递特定的文件路径而不是 file:///like file:///sdcard