如何访问getFilesDir()作为环境变量?

编程入门 行业动态 更新时间:2024-10-26 20:30:49
本文介绍了如何访问getFilesDir()作为环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要访问

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.

然而,一个上下文可几乎无处不在的Andr​​oid应用程序,这不应该是一个真正的问题。

However, a Context is available practically everywhere in an Android application so this shouldn't really be a problem.

跟帖:

怎么样 Environment.getDataDirectory()?我怎样才能数据\数据从数据\数据\ com.Myapp 使用EnvironmentVar?

how about Environment.getDataDirectory()? how can i get data\data as from data\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()作为环境变量?

本文发布于:2023-11-23 17:36:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622315.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境变量   getFilesDir

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!