Android Question Get Icon, Application Name, and Version name of APK files on SD card

cambopad

Active Member
Licensed User
Longtime User
Dear all B4A devs!

How can I get all of the information such as icon, application name, and version name of the APK files (which are NOT already installed) stored on the SD card. I googled and found some answers on Stackoverflow, but unable to convert it to b4a as I know nothing about Java. This is the sub in Java to get the Icon :


B4X:
public Drawable getApkIcon(String path){   
    PackageManager pm = getPackageManager();   
    PackageInfo info = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);   
    if(info != null){   
        ApplicationInfo appInfo = info.applicationInfo;

        if(Build.VERSION.SDK_INT >= 8){
            appInfo.sourceDir = path;
            appInfo.publicSourceDir = path;
        }

        return appInfo.loadIcon(pm);
    }        
    return null;
}

Can anyone help to convert this to B4a?

Thanks you :)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use the new inline java feature to run this code.

Add the following imports at the beginning of the Java code:
B4X:
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Build;
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
B4X:
Dim pm As PackageManager 'Phone lib 
pm.GetApplicationIcon
pm.GetApplicationLabel
pm.GetVersionName
pm.GetVersionCode
?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Oh, endeed, sorry, my fault, did not notice that about separate APK.
 
Upvote 0
Top