Android Question PackageManager: how to show list packages switched off

fransvlaarhoven

Active Member
Licensed User
Longtime User
Hello,

- with PM.GetInstalledPackages, one gets a list with all packages on the Phone
- a user can disable/uninstall an app

How can I get the list off all app's that are disabled?
 

DonManfred

Expert
Licensed User
Longtime User
How can I get the list off all app's that are disabled?
The B4A Packagemanager does not expose this feature. Maybe with javaobject.

Based on https://stackoverflow.com/questions/25342883/check-if-app-is-enabled-or-disabled-using-package i put the solution there into a small lib....

Check the library attached by yourself please. I did not tried it so far...

Code something like
B4X:
dim pmx as PMX
'
if pmx.checkAppDeactivated("packagename") then
log("app is deactivated")
else
log("App not deactivated")
end if
 

Attachments

  • PMX.xml
    724 bytes · Views: 331
  • PMX.jar
    778 bytes · Views: 235
Upvote 0

fransvlaarhoven

Active Member
Licensed User
Longtime User
Thank You for your fast response.

However, ther seems to be a small problem with:

if pmx.checkAppDeactivated("packagename") then

the IDE generates the error "Cannot assign Void value"

If i change the definition of the return value in PMX.XML, the IDE accepts the code but the compiler generates an error
 
Last edited:
Upvote 0

fransvlaarhoven

Active Member
Licensed User
Longtime User
unfortunately, this also failes:

main_activity_click (java line: 480)
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.app.Activity.getPackageManager()' on a null object reference
at de.donmanfred.PMSwrapper.checkAppDeactivated(PMSwrapper.java:22)
 
Upvote 0

fransvlaarhoven

Active Member
Licensed User
Longtime User
Ok. changed it a bit again... The name was not really correct. Try this example and new version...

This time including working example

still something missing:

I tested it with the following routine:

B4X:
 Dim pmx As PMX
 Dim PM As PackageManager
 Dim availablepackages As List= PM.GetInstalledPackages
 If availablepackages.IsInitialized= True Then
    For lp= 0 To availablepackages.Size - 1
       Dim packagename As String= availablepackages.Get(lp)
       If packagename.ToLowerCase.Contains("smessenger")= True Then
          LogColor("found " & packagename, Colors.blue)
          If pmx.getAppStatus(packagename) Then
             LogColor(packagename & " is deactivated", Colors.red)
          Else
             LogColor(packagename & " is NOT deactivated", Colors.blue)
          End If
       Else If packagename.ToLowerCase.Contains("com.android.chrome")= True Then
          LogColor("found " & packagename, Colors.blue)
          If pmx.getAppStatus(packagename) Then
             LogColor(packagename & " is deactivated", Colors.red)
          Else
             LogColor(packagename & " is NOT deactivated", Colors.blue)
          End If
       End If
     Next
 End If

both applications are showed as "deactivated" while both applications are running on the Phone
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
pmx.getAppStatus(packagename) Then
LogColor(packagename & " is deactivated", Colors.red)
should be (remember; i changed the lib)....

... is ENABLED
else
... is NOT ENABLED (deactivated)

I tried it with a app i know it is deactivated. see my example. in this case i got the message that the app is deactivated like expected.

getAppStatus = get apps isEnabled status...
 
Upvote 0

fransvlaarhoven

Active Member
Licensed User
Longtime User
I guess you should use explicit calls to check for specific apps...
com.android.chrome for example. No need to use the b4a packagemanager in this case i guess....

checking my test, I realised that I've made a stupid mistake; Your routine works.:):):)

Thank You for Your help
 
Upvote 0
Top