简体   繁体   English

如何在Android中以编程方式获取重命名.APK文件名?

[英]How to get rename .APK file name in Android programmatically?

Here is my problem. 这是我的问题。 Please help me to find the way. 请帮助我找到方法。

The problem is: I have an .APK file named Test.APK and I have rename the file name to MyTest.APK, and now i want to get the MyTest file name into my source code programmatically, but i could not get the MyTest name. 问题是:我有一个名为Test.APK.APK文件,并且已将文件名重命名为MyTest.APK,现在我想以编程方式将MyTest文件名添加到我的源代码中,但是我无法获得MyTest名称。 All i can get is the Test because my application label name is Test. 我只能得到测试,因为我的应用程序标签名称是Test。 I don't want to get the package name as well, because the package name also have the same Test. 我也不想获取软件包名称,因为软件包名称也具​​有相同的Test。 Now Please help me some one to follow my next steps. 现在,请帮助我,按照我的下一步操作。

Many thanks in advance. 提前谢谢了。

I have seen a related question but there is nothing to relevant solution, the link is: Getting name of original .APK file in Android 我已经看到一个相关问题,但是没有相关解决方案,链接是: 在Android中获取原始.APK文件的名称

According to your question, 根据您的问题,

How to get rename .APK file in Android programmatically? 如何以编程方式在Android中获取重命名.APK文件?

Here's how: 这是如何做:

    File file = new File("/mnt/sdcard/Test.apk"); // your apk's location
    if (file.exists()){
        String path = file.getAbsolutePath();
        String name = path.substring(path.lastIndexOf('/')); // returns Test.apk
        String newName = "MyTest.apk";
        if (file.renameTo(new File(file.getParent(), newName))) {
            System.out.println("Success rename");
            name = path.substring(path.lastIndexOf('/')); // returns MyTest.apk
            System.out.println("New name is "+name);
        }
    }

我知道这是一个老问题,但是我要做的方法是通过build.config文件。

setProperty("archivesBaseName", "new_apk_name")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM