1

Take screenshots and save android问题中,有人被告知如何将在我的应用中创建的图像保存到 SD 卡。现在我正在尝试上传图片,但首先我需要找到如何获取路径。我使用的整个代码在最后一个问题中,我需要知道如何获取我保存的图像的路径。有什么建议么?

4

3 回答 3

0

Check these lines:

String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/MyDraw");    
myDir.mkdirs();
file = new File (myDir, name+".png");

file is the File object that points to the location where the Bitmap is saved.

于 2013-05-22T16:44:22.767 回答
0

When onActivityResult() gets called back in your application, the intent contains the uri of where the file was stored. Pull it out of there and save it

于 2013-05-22T16:44:36.900 回答
0

First of all, you need the name that the user entered to save the filename with. You can save the filename the user inputted by saving to a pref (or they just entered it, then you should still have it). Once you have the filename, you can simply get the file by:

String fileName = //get the file name
File f = new File(Environment.getExternalStorageDirectory(), "/MyDraw");
f = new File(f, fileName);

If you don't know the filename, you can loop through the file directory:

File dir = new File(Environment.getExternalStorageDirector(), "/MyDraw");
for (File f : dir.listFiles()) {
    //Do something with this file
}
于 2013-05-22T16:45:02.800 回答