android 如何从包中获取文件名

发布于 2024-10-07 01:50:07 字数 150 浏览 0 评论 0原文

这是 Android 问题。
有谁知道如何从包中而不是从资源文件夹中获取文件名(作为字符串)?
例如,如果normal.xml存储在src/com.example.xml/normal.xml中,我如何获取字符串形式的文件名?
谢谢你!

This is Android question.
Does anyone know how I can get file names (as String) from the package and not from the resource folder?
For example, if normal.xml is stored in src/com.example.xml/normal.xml, how can i get the name of the file as String?
Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小梨窩很甜 2024-10-14 01:50:07

如果您有权访问 .apk(在安装之前,或者因为它是您的应用程序,或者因为它安装在没有复制保护的设备上并且您知道其确切路径名),则可以将其作为 zip 文件读取。

If you have access to the .apk (either before installation, or because it is your application, or because it is installed on the device without copy protection and you know its exact path name) you can read it as a zip file.

中性美 2024-10-14 01:50:07

您可以将类似的内容放置在同一名称空间中加载的任何 Activity 的 OnCreate() 方法中:

@Override
public void onCreate(Bundle savedInstanceState) {
    //Other logic...
    AssetManager mgr = getAssets();
    String[] list = mgr.list("./");
    for(String s : list){
        Log.v("Found file:", s);
    }
    //Other logic...
}

这将列出在您的 Activity 所在的同一文件夹中找到的所有文件。您可以将 "./" 更改为此 Activity 所在的 com.example.xml 目录中您希望的任何相对路径。

You can place something like this in the OnCreate() method of whatever Activity is loaded in that same namespace:

@Override
public void onCreate(Bundle savedInstanceState) {
    //Other logic...
    AssetManager mgr = getAssets();
    String[] list = mgr.list("./");
    for(String s : list){
        Log.v("Found file:", s);
    }
    //Other logic...
}

This will list all of the files found in the same folder that you have your Activity. You can change "./" to be whatever relative path you would wish from the com.example.xml directory where this Activity lives.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文