Android Question How to Launch build in Caclculator

trepdas

Active Member
Licensed User
Hello good b4x people,

I am trying to launch the build in calculator using intent but with no success.
Do I need to declare something in the manifest?

used Erel's example (from 2012) but with no suucess :

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim i As Intent
   i.Initialize("", "")
   i.SetComponent("com.android.calculator2/.Calculator")
   Try
      StartActivity(i)
   Catch
      ToastMessageShow("Calculator app not found.", True)
   End Try
End Sub

log:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.calculator2/com.android.calculator2.Calculator}; have you declared this activity in your AndroidManifest.xml?
 

udg

Expert
Licensed User
Longtime User
If you didn't before, read through all of this thread.
Stackoverflow clould be of inspiration too.
 
Upvote 0

jantorun

New Member
Licensed User
Longtime User
Hello,

may be a little bit outdated but some years ago I used this with success:

Call Android calculator:
Sub Calculator
  Dim Cal As Intent
  Dim I As Int
  Dim pm As PackageManager
  Dim packages As List
  Dim Packname As String
  Dim Calculatoranwendung As String
  Cal.Initialize("", "")
  Try
    packages = pm.GetInstalledPackages
    For I = 0 To packages.Size - 1
      Packname = packages.Get(I)
        If Packname.Contains("alculator") = True Then
          Calculatoranwendung = Packname
          Exit
        End If
    Next
    Cal = pm.GetApplicationIntent(Calculatoranwendung)
    StartActivity(Cal)
  Catch
    Msgbox("Calculator not found on System!","Error")
  End Try
End Sub

You can also extend the code
<If Packname.Contains....>
to ask for your favorite calculator installed on your device first and use this one before searching for the default.

Jan
 
Upvote 0
Top