在问题Take screensot and save android中,有人告知如何将我的应用中创建的图像保存到SD卡。现在我试图上传图片,但首先我需要找到如何获取路径。我使用的整个代码是最后一个问题,我需要知道如何获取我保存的图像的路径。有什么建议吗?
答案 0 :(得分:0)
检查这些行:
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/MyDraw");
myDir.mkdirs();
file = new File (myDir, name+".png");
file
是File对象,它指向保存位图的位置。
答案 1 :(得分:0)
在应用程序中回调onActivityResult()
时,意图包含文件存储位置的uri。将它拉出并保存
答案 2 :(得分:0)
首先,您需要用户输入的名称来保存文件名。您可以通过保存到pref保存用户输入的文件名(或者他们刚刚输入,然后您仍然可以使用它)。获得文件名后,您只需通过以下方式获取文件:
String fileName = //get the file name
File f = new File(Environment.getExternalStorageDirectory(), "/MyDraw");
f = new File(f, fileName);
如果您不知道文件名,可以遍历文件目录:
File dir = new File(Environment.getExternalStorageDirector(), "/MyDraw");
for (File f : dir.listFiles()) {
//Do something with this file
}