'I want to share installed apps with their original name but the all apps name is similar base.apk when the is get from file

I have try to change name from it's absolute path but when i again get the list of apps list is not updated. I want to share apps using udp and tcp socket

 list = AppUtils.getAppList(context);

            for (int i = 0; i < list.size(); i++) {
                AppEntity appEntity = list.get(i);
                //TODO Rename File
                String filepath = appEntity.getAbsolutePath();
                String path = filepath.substring(filepath.lastIndexOf("/") + 1);
                File file = new File(filepath);
                File from = new File(file.getName());
                File to = new File(appEntity.getAppName());
//                if (from.exists()) {
                from.renameTo(to);

                Log.d("FileName", "doInBackground: " + to);
//                }
//                File file1 = new File(filepath);
//                Log.d("FileName", "doInBackground: "+file1.getName());
            }
            updatedList = AppUtils.getUpdatedAppList(context);


//TODO updated data
    public static List<AppEntity> getUpdatedAppList(Context context) {
        PackageManager pm = context.getPackageManager();
        List<PackageInfo> packageInfos = pm.getInstalledPackages(0);
        List<AppEntity> appInfos = new ArrayList<>();
        for (PackageInfo packageInfo: packageInfos) {

            ApplicationInfo app = packageInfo.applicationInfo;
            if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                // Non-system application
                File apkfile = new File(app.sourceDir);
                PackageStats stats = new PackageStats(packageInfo.packageName);
                AppEntity appInfo = new AppEntity(app.sourceDir);
                appInfo.setPackageName(packageInfo.packageName);
                appInfo.setVersionCode(packageInfo.versionCode);
                appInfo.setVersionName(packageInfo.versionName);
                appInfo.setUid(app.uid);
                appInfo.setIcon(pm.getApplicationIcon(app));
                File file = new File(appInfo.getAbsolutePath());

                appInfo.setAppName(file.getName());
                appInfo.setCacheSize(stats.cacheSize);
                appInfo.setDataSize(stats.dataSize);
                appInfos.add(appInfo);
            }

        }

        return appInfos;

Log cat

 doInBackground: SM Downloader.apk
2022-02-24 12:09:04.386 22246-22296/com.jubilant.tech.share D/FileName: doInBackground: · Zero Flow Mutual Assistance Upgrade Application.apk
2022-02-24 12:09:04.386 22246-22296/com.jubilant.tech.share D/FileName: doInBackground: Quiz.apk
2022-02-24 12:09:04.387 22246-22296/com.jubilant.tech.share D/FileName: doInBackground: Six Kalma.apk

Help please how to share installed apps with their original names



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source