Bug: PackageManger Intents

m0narX

Member
Licensed User
Longtime User
Function GetInstalledPackages returns all installed packages, but package may have a few intents for launch, as in fact we need function GetIstalledIntents(filter) (filter for example: "android.intent.category.LAUNCHER")
Also need function GetIntentIcon instead GetApplicationIcon, because each intent may have it's own icon
For example try this functions on HTC Device with HTCCamera application(this application have two intents)
Thank you.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't see any bug here.
GetApplicationIntent calls PackageManager.getLaunchIntentForPackage which is described in the SDK:
Return a "good" intent to launch a front-door activity in a package, for use for example to implement an "open" button when browsing through packages. The current implementation will look first for a main activity in the category Intent.CATEGORY_INFO, next for a main activity in the category Intent.CATEGORY_LAUNCHER, or return null if neither are found.

Also GetApplicationIcon just calls the native PackageManager.getApplicationIcon which returns the application icon.
 

m0narX

Member
Licensed User
Longtime User
But how about applications that have two ar more intents to launch?
As i wrote above HTC Camera has two intents(Photo Camera and Video Capture), and then i try to start camera intent from list of packages, i have an error(
 

m0narX

Member
Licensed User
Longtime User
B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim Ph As Phone
   Dim Pm As PackageManager
   Dim Packages As List
   Dim ListView1 As ListView
   Dim Intent1 As Intent
   Dim Icon As BitmapDrawable
   Dim ImageView1 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("main")
   Header = Ph.GetResourceDrawable(33619990)(
   ImageView1.Bitmap = Header.Bitmap
   ProgressDialogShow("Создание списка пакетов")
   Packages = Pm.GetInstalledPackages
   For i=0 To Packages.Size - 1
      'Dim Intent1 As Intent
      Intent1 = Pm.GetApplicationIntent(Packages.Get(i))
      If Intent1.IsInitialized Then
         Try
            Icon = Pm.GetApplicationIcon(Packages.Get(i))
            ListView1.AddTwoLinesAndBitmap2(Pm.GetApplicationLabel(Packages.Get(i)), Packages.Get(i), Icon.Bitmap, Packages.Get(i))
         Catch
            ListView1.AddTwoLines(Pm.GetApplicationLabel(Packages.Get(i)), Packages.Get(i))         
         End Try
         DoEvents
      End If
   Next
   ProgressDialogHide
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
   Intent1 = Pm.GetApplicationIntent(Value)
   Icon = Activity.Background
   If Intent1.IsInitialized Then
      StartActivity(Intent1)
   End If
End Sub

And then i select HTC Camera application i get an error.
 

m0narX

Member
Licensed User
Longtime User
Header = Ph.GetResourceDrawable(33619990)( - This line don't needed
 

m0narX

Member
Licensed User
Longtime User
I get that error
 

Attachments

  • screenshot.jpg
    screenshot.jpg
    18.9 KB · Views: 329

m0narX

Member
Licensed User
Longtime User
But it's camera app instilled on all HTC devices. Is another way to launch this application?
 
Top