在非root用户设备上,我可以使用run-as带有我的包名称的命令导航到包含数据库的数据文件夹.我满意的大多数文件类型只是查看,但我想从Android设备拉数据库.
是否有一个download copy或move亚行外壳,这部分命令?我想下载数据库文件并使用数据库浏览器查看其内容.
这里的一个答案涉及将整个应用程序包转换为压缩存档,但是一旦完成并移动到机器上,如何提取该存档就没有进一步的答案,当我可能有一个更直接的解决方案开始
使用AVD Manager创建新的Android 4.4虚拟设备时,我无法使内部存储大于200MB.
512MB是我想设置的内部存储大小.
我试过了:
这种情况发生在ARM和Intel Atom x86 CPU上.
现在,当我切换到Android 3.0(ARM)时,我可以简单地使用AVD Manager来调整它的内容.Android 4.4有问题吗?我错过了什么吗?或者可能的解决方法?
android emulation android-virtual-device android-emulator internal-storage
Android 6.0 Marshmallow推出了Adoptable Storage,这项功能允许使用SD卡作为内部存储.
是否可以通过ADB shell命令激活可采用的存储?
我正在开发一个简单的android应用程序,我需要在内部存储设备中编写一个文本文件.我知道关于这个问题有很多问题(和答案),但我真的无法理解我在做错的方式.
这是我在活动中使用的一段代码,用于编写文件:
public void writeAFile(){
String fileName = "myFile.txt";
String textToWrite = "This is some text!";
FileOutputStream outputStream;
try {
outputStream = openFileOutput(fileName , Context.MODE_PRIVATE);
outputStream.write(textToWrite.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我真的不明白我在做什么错.另外,我已经在Android Studio和我的手机上的模拟器上尝试了这个项目,以便了解我做错了什么,但即使使用该项目,也没有文件既没有写在手机上也没有写在模拟器上.
编辑:我知道没有文件写入我的内部存储,因为我尝试读取文件的内容,在我写完之后,使用以下代码:
public void ReadBtn(View v) {
//reading text from file
try {
FileInputStream fileIn=openFileInput("myFile.txt");
InputStreamReader InputRead= new InputStreamReader(fileIn);
char[] inputBuffer= new char[READ_BLOCK_SIZE];
String s="";
int charRead;
while ((charRead=InputRead.read(inputBuffer))>0) {
String readstring=String.copyValueOf(inputBuffer,0,charRead);
s +=readstring;
}
InputRead.close();
textmsg.setText(s);
} catch (Exception e) { …Run Code Online (Sandbox Code Playgroud) 我需要在我的应用程序中使用一些文件.它们保存在资产文件夹中.我看到SO上的讨论,文件从资产文件夹复制到内部存储上的/ data/data /,然后被使用.我得到了代码,但我没有得到的是,将资产复制到内部存储需要什么?如果有人有这方面的经验,请帮忙!
当我从内部存储(图库)获取图像时,这是我的代码.在棒棒糖文件路径中,返回始终为null.
if (requestCode == PICK_IMAGE) {
if(resultCode == RESULT_OK){
//image successfully picked
// launching upload activity
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
columnindex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
file_path = cursor.getString(columnindex);
Log.d(getClass().getName(), "file_path"+file_path);
fileUri = Uri.parse("file://" + file_path);
cursor.close();
launchUploadActivity(true, PICK_IMAGE);
}else if (resultCode == RESULT_CANCELED) {
// user cancelled recording
Toast.makeText(getApplicationContext(),"User cancelled image selection", Toast.LENGTH_SHORT).show();
} else {
// failed to record video
Toast.makeText(getApplicationContext(),"Sorry! failed to pick image", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud) android filepath imageview internal-storage android-5.0-lollipop
我编写了一个创建文件并将数据写入文件并存储在内部存储中的方法.当我得到文件的绝对路径或路径[我已添加日志消息来试验文件上的操作]时,它显示该文件是在根目录下创建的,它位于/ data/data/mypackagename下/files/filename.txt.不过,我可以在DDMS上找到这些文件夹,在那里我可以找到由我编写的方法创建的文件.但我也无法打开该文件,因为我没有权限.
当我查看我的Android设备时,我找不到这些目录.我查看了堆栈溢出,有些人回答说内部存储中的/ data/data文件夹是隐藏的,要访问它们我必须根据我不想做的设备.
下一步方法:Android设备上有一个名为MyFiles的文件夹[我正在使用运行Android 4.4进行测试的Galaxy Tab 4].在此文件夹下有设备存储目录,其中包含各种文件夹,如文档,图片,音乐,铃声,Android等等.因此,相机,电子表格应用等应用程序可以将图片写入或保存到图片文件夹中或文件夹中的txt文件.同样,如何将我在函数中创建的文件写入Documents文件夹或可通过设备访问的任何其他文件夹.请帮助我怎么做,任何帮助表示赞赏.
以下是我写的代码:
public void addLog(String power_level){
// creates a logFile in the root directory of the internal storage of the application.
// If the file does not exists, then it is created.
Log.d("AppendPower", "In addLog method");
//File logFile = new File(((Context)this).getFilesDir(), "logFile.txt");
File logFile = new File(getFilesDir(), "logFile.txt");
Log.d("FilesDir Path", getFilesDir().getAbsolutePath());
Log.d("FilesDir Name", getFilesDir().getName());
Log.d("Path on Android", logFile.getPath());
Log.d("Absolute Path on Android", logFile.getAbsolutePath());
Log.d("Parent", logFile.getParent());
if(!logFile.exists()){
try{
logFile.createNewFile();
}catch(IOException io){
io.printStackTrace();
}
} …Run Code Online (Sandbox Code Playgroud) 考虑上面的图片.它显示内部存储中的文件夹和文件.我的问题是我无法获得内部存储的绝对路径.我试过用过
String path = getFilesDir().getAbsolutePath();
但它给了我应用程序存储的路径.我的目标是将文件从我的应用程序的私有存储备份到内部存储的顶部.我无法在Web上找到解决方案,也无法在堆栈溢出时找到解决方案.建议解决这个问题!
我有一种方法从url下载图像并将其保存在内部存储的文件夹中
public void saveDynamicImage(String url,String fileName, String folderName) {
InputStream iStream;
BufferedInputStream buffInputStream;
ByteArrayBuffer byteArray = null;
try {
HttpGet httpGet = new HttpGet(url);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = httpClient.execute(httpGet);
iStream = httpResponse.getEntity().getContent();
buffInputStream = new BufferedInputStream(iStream, 8 * 1024);
byteArray = new ByteArrayBuffer(50);
int current = 0;
while ((current = buffInputStream.read()) != -1) {
byteArray.append((byte) current);
}
} catch (ClientProtocolException e1) {
} catch (IOException e1) {
}
File dynamicImageDir = context.getDir(AppConstants.DYNAMIC_IMAGE, Context.MODE_PRIVATE);
File appNamefileDir = …Run Code Online (Sandbox Code Playgroud) 众所周知:
当用户卸载您的应用程序时,系统会从内部存储中删除所有应用程序的文件.
当用户更新应用程序时是否会发生同样的事情?
raw/夹中有一个文件,每次运行我的应用程序时都会移动到内部存储器(如果它尚未移动):
//On Application onCreate() method:
InputStream jsonFile = ctx.getResources().openRawResource(R.raw.data);
File file = ctx.getFileStreamPath(Helper.FILE_NAME);
if(file.exists())
return; //Exit because the file is already been copied.
FileOutputStream fos = ctx.openFileOutput(Helper.FILE_NAME, Context.MODE_PRIVATE);
copyFile(fos, jsonFile); //my method to copy files.
Run Code Online (Sandbox Code Playgroud)
该文件可能会在以后的应用程序版本中更新.如果系统在更新应用程序时删除内部文件,则上述代码将为"确定".但是,如果不是这种情况,那么我需要执行另一项检查以确保用户具有最新版本.像这样的东西:
if(file.exists() && fileVersion == lastVersion)
Run Code Online (Sandbox Code Playgroud)