Android的获得外部存储绝对路径 [英] Android getting external storage Absolute Path

查看:640
本文介绍了Android的获得外部存储绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想下载一些文件,并将它们保存到手机/标签的内部存储。试图在三星Galaxy Note 2和Galaxt选项卡10.1。当我使用 /存储/ sdcard0 / 对他们的code成功运行,但是当我使用 Galaxy Nexus的3 在code失败。

我想获得phoe或标签的内部存储的绝对路径绝对路径

是否有可能,如果是的话怎么办?

解决方案
  

当我使用/存储/ sdcard0 /对他们的code成功运行,但是当我使用Galaxy Nexus的3 code失败。

/存储/ sdcard0 / 不是内部存储。它是外部存储

(顺便说一句,因为没有命名为Galaxy Nexus的3的设备,我假设你只是意味着Galaxy Nexus的)

要找到的的内部的存储你的应用程序,使用 getFilesDir(),呼吁任何上下文(比如你的活动,获得文件对象。

要在获得一个位置的外部的存储独特的为您的应用程序,使用 getExternalFilesDir(),呼吁任何上下文(比如你的活动,获得文件对象。

要获得的标准的位置的外部的存储常用类型的文件(如电影),使用 getExternalStoragePublicDirectory()环保

要获得的根的外部的存储,使用 getExternalStorageDirectory()环境。然而,这被认为是草率的编程时下,因为它鼓励开发人员只是把文件放在任意位置。

I want to download some files and save them into the internal storage of the phone/tab. Tried on Samsung Galaxy Note 2 and Galaxt Tab 10.1. When I use /storage/sdcard0/ on them the code runs successfully but when I use Galaxy Nexus 3 the code fails.

I want to get absolute path of the phoe or tab's internal storage' Absolute Path.

Does it possible, if so how?

解决方案

When I use /storage/sdcard0/ on them the code runs successfully but when I use Galaxy Nexus 3 the code fails.

/storage/sdcard0/ is not internal storage. It is external storage.

(BTW, since there is no device named "Galaxy Nexus 3", I am assuming that you simply meant "Galaxy Nexus")

To find locations on internal storage for your app, use getFilesDir(), called on any Context (such as your Activity, to get a File object.

To get a location on external storage unique for your app, use getExternalFilesDir(), called on any Context (such as your Activity, to get a File object.

To get a standard location on external storage for common types of files (e.g., movies), use getExternalStoragePublicDirectory() on Environment.

To get the root of external storage, use getExternalStorageDirectory() on Environment. This, however, is considered sloppy programming nowadays, as it encourages developers to just put files in random locations.

这篇关于Android的获得外部存储绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆