【问题标题】:How I get android/data/"package name"/我如何获得 android/data/"package name"/
【发布时间】:2021-10-21 18:26:29
【问题描述】:
File filePath = new File(Environment.getDataDirectory().getAbsolutePath());

但我只返回/data,所以/data在哪里以及我如何获取andrid/data/"package_name"/

【问题讨论】:

  • getFilesDir() 和 getExternalFilesDir()。
  • 感谢您的回复,我使用 getFileDir() 和 getExternalFilesDir(),如果我与 Environment 一起使用,则它没有显示任何功能,如果我单独使用,则它不存在。
  • 我得到了答案,但我觉得这很不合规矩 - File filePath = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Android/data/com.rigup.memest/files /Download/"+视频名称);
  • ????你在做什么?您应该只查看 getFilesDir() 和 getExternalFilesDir(null) 的绝对路径。请先说出他们的价值观。您不需要环境,而是需要上下文。你在哪一门课上试过?
  • 是的,你说得对,我使用的是不同的类,我必须使用上下文。非常感谢您的帮助。

标签: java android android-studio file


【解决方案1】:

虽然这不是从数据文件夹中获取包名称的写入方式,但这可以用作临时解决方案:

File file=getApplicationContext().getFilesDir();

感谢@blackapps 让解决方案更加简单。

【讨论】:

  • 非常感谢,在您的代码的帮助下,我的项目运行良好..
  • 我已经更新了我的答案。您可以通过输入逗号来添加孩子。示例:File file=new File(getApplicationContext().getFilesDir().getAbsolutePath(),"/Download"+VideoName)
  • 那就做对吧:File file=new File(getApplicationContext().getFilesDir(), "Download/"+VideoName).
  • File file = new File(getApplicationContext().getFilesDir().getAbsolutePath()); 那只是:File file = getApplicationContext().getFilesDir();
  • 是的,你们俩都是对的!我运行你的代码 blackapps 和丹麦语。再次感谢您如此快速的回复和高效的回答。我真的很感激。
猜你喜欢
  • 1970-01-01
  • 2012-03-04
  • 1970-01-01
  • 1970-01-01
  • 2016-02-13
  • 2021-07-14
  • 1970-01-01
  • 2014-12-31
  • 1970-01-01
相关资源
最近更新 更多