Android Question How to get an installed app apk's path

Ohanian

Active Member
Licensed User
Longtime User
Hi,

i have an option in my app the lets the user to share the app with others, but the problem is that i don't know how to get the apk path of my app.
found this (with shell) :
B4X:
http://stackoverflow.com/questions/11012976/get-apk-of-installed-app

with shell i can get the path with this command :
adb shell pm path com.xxx.yyyyyy

the result is something like this :
package:/data/app/com.xxx.yyyyyy-115.apk

and this code :
B4X:
final PackageManager pm = getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages =  pm.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo packageInfo : packages) {
    Log.d(TAG, "Installed package :" + packageInfo.packageName);
    Log.d(TAG, "Apk file path:" + packageInfo.sourceDir);
}

but i don't know how to get the sourceDir with applicationmanager.

any help is appreciated.
 

Ohanian

Active Member
Licensed User
Longtime User
Found it :

B4X:
Sub GetActivitiesInfo(package As String) As Object
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod("getPackageManager")
   r.Target = r.RunMethod3("getPackageInfo", package, "java.lang.String", 0x00000001, "java.lang.int")
   Return r.GetField("applicationInfo")
End Sub

Sub GetSourceDir(AppInfo As Object) As String
    Try
        Dim r As Reflector      
        r.Target = AppInfo
        Return r.GetField("sourceDir")     
    Catch
        Return ""
    End Try
End Sub
 
Upvote 0
Top