0

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. All i can get is the Test because my application label name is Test. I don't want to get the package name as well, because the package name also have the same 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

Community
  • 1
  • 1
Pranob
  • 641
  • 6
  • 11

2 Answers2

0

According to your question,

How to get rename .APK file in Android programmatically?

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);
        }
    }
Anggrayudi H
  • 14,977
  • 11
  • 54
  • 87
  • Thanks for your sincere effort, @Anggrayudi H. But my question was in short " How to rename the generated APK file?" if you got any idea please let me know. – Pranob Oct 25 '16 at 07:44
0

I know this is an old question but the way I have done it is through the build.config file.

setProperty("archivesBaseName", "new_apk_name")
Stillie
  • 2,647
  • 6
  • 28
  • 50