Reputation: 36289
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
Upvotes: 0
Views: 1465
Reputation: 1626
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
Upvotes: 1