adb Push:文件去哪里了?
我创建了一个非常简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK 没有 root 权限你无法访问
/data
。您应该将文件添加到Activity.getFilesDir()
,它会转换为/data/data/com.yourapp/files
AFAIK you can't access
/data
without root permission. You should add your files toActivity.getFilesDir()
which translates to/data/data/com.yourapp/files