adb Push:文件去哪里了?

发布于 2025-01-02 04:03:57 字数 1476 浏览 1 评论 0原文

我创建了一个非常简单的 Android 应用程序来测试 adb Push。我基本上试图查看存储在数据目录中的文件列表。使用adb push添加文件,我希望看到列表发生变化,但尽管这些文件显示了DDMS Perspective,但它们并不位于我的应用程序的数据目录中正在查看(因此`Activity 显示EMPTY,如下面的代码所示)。我应该走的正确道路是什么,或者我做错了什么?

代码:

import java.io.File;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class TestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(updateView());
    }

    public View updateView() {
        File[] files = Environment.getDataDirectory().listFiles();
        LayoutInflater inflater;
        inflater = (LayoutInflater)    this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflater.inflate(R.layout.main, null);
        TextView tv = (TextView) v.findViewById(R.id.text01);
        String s = "";
        if (files != null) {
            for (File f : files) {
                s += f.getName() + "\n";
            }
        }
        else {
            s = "EMPTY";
        }
        tv.setText(s);
        return v;
    }
}

命令:

./adb push myfile.txt /data/myfile.txt

I have created a very simple android app to test adb push. I am basically trying to view a list of files stored in the data directory. Using adb push to add files, I was expecting to see the list change, but although the files show up the DDMS Perspective, they are not in the data directory that my app is looking at (and thus the `Activity is displaying EMPTY, as shown in the code below). What is the correct path I should be pushing to, or what am I doing wrong?

The code:

import java.io.File;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class TestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(updateView());
    }

    public View updateView() {
        File[] files = Environment.getDataDirectory().listFiles();
        LayoutInflater inflater;
        inflater = (LayoutInflater)    this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflater.inflate(R.layout.main, null);
        TextView tv = (TextView) v.findViewById(R.id.text01);
        String s = "";
        if (files != null) {
            for (File f : files) {
                s += f.getName() + "\n";
            }
        }
        else {
            s = "EMPTY";
        }
        tv.setText(s);
        return v;
    }
}

The command:

./adb push myfile.txt /data/myfile.txt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青萝楚歌 2025-01-09 04:03:57

AFAIK 没有 root 权限你无法访问 /data 。您应该将文件添加到 Activity.getFilesDir() ,它会转换为 /data/data/com.yourapp/files

AFAIK you can't access /data without root permission. You should add your files to Activity.getFilesDir() which translates to /data/data/com.yourapp/files

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文