Android Question Get my own app info with code

Rizal Putra

Member
Licensed User
Longtime User
How to get alll information/properties about my own app, like package name, version code, version name, icon.

In VB.NET, usually i use this code :
B4X:
Dim Name, Version As String

Name = Application.ProductName
Version = Application.ProductVersion
 

Rizal Putra

Member
Licensed User
Longtime User
How to get Package Name from current project ?
Because i will use this code for "About" activity for all my project, so i don't need change the code inside, just copy-paste Modeule file (use "Add Existing Module" menu)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You need REFLECTION and JAVAOBJECTS libs

B4X:
Sub Process_Globals
  Dim ActMan As JavaObject
End Sub
Sub Activity_Create(FirstTime As Boolean)
  Dim R As Reflector
  R.Target=R.GetContext
  'Get Activity Manager Object
  ActMan = R.RunMethod2("getSystemService","activity","java.lang.String")
  Dim TaskInfo As JavaObject = ActMan.RunMethod("getRunningTasks",Array As Object(1))
  Dim CompInfo As JavaObject = TaskInfo.RunMethodJO("get",Array As Object(0)).GetField("topActivity")
  Dim PackageName As String = CompInfo.RunMethod("getPackageName",Null)
  Log(PackageName)
End Sub

Please note that you need the permission GET_TASKS

Add this in the manifesteditor

AddPermission(android.permission.GET_TASKS)

I found the code here. Thanx to @stevel05 :cool:
 
Last edited:
Upvote 0
Top