如何访问getFilesDir()作为环境变量? [英] how to access getFilesDir() as an environment variable?
问题描述
我要访问
getFilesDir()
这是一个上下文方法
有没有什么办法可以同样访问到我访问外部存储的方式是什么?
Is there any way to access it similarly to the way i access external-storage?
Environment.getExternalStorageDirectory();
意义的环境变量?
也许应用静态上下文?因为我想从非上下文类调用这个(相同的应用程序服务,而不是一个活动)
Maybe application static context? as i want to call this from a non-context class (same app service, but not an activity)
推荐答案
这是不可能的。
上下文
getFilesDir()
返回绑定到你的包和一个路径背景
才能访问包名。
Context
getFilesDir()
returns a path that is bound to your package and the Context
is required to access the package name.
环保
是不同的,因为只有公用的在同一个运行时运行的所有应用程序的常量。
Environment
is different as there's only constants that are common to all apps running on the same runtime.
然而,一个上下文
可几乎无处不在的Android应用程序,这不应该是一个真正的问题。
However, a Context
is available practically everywhere in an Android application so this shouldn't really be a problem.
跟帖:
怎么样 Environment.getDataDirectory()
?我怎样才能数据\数据
从数据\数据\ com.Myapp </ code>使用EnvironmentVar?
how about
Environment.getDataDirectory()
? how can i getdata\data
as fromdata\data\com.Myapp
using EnvironmentVar?
Environment.getDataDirectory()
只是返回通用于所有的应用程序数据目录的一部分。例如, /数据/数据
。
Environment.getDataDirectory()
just returns the part of the data directory common to all apps. For example, the /data/data
.
要得到您自己的文件目录( getFilesDir()
),您的包名和/文件
需要要追加到它。 上下文
的实施做这个给你。
To get your own files dir (getFilesDir()
), your package name and "/files"
need to be appended to it. Context
implementation does this for you.
这篇关于如何访问getFilesDir()作为环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!