Android Question Get my app package name

Air

Member
Licensed User
Longtime User
Noob question: how can i save my app's package name in a string variable?

If your Package-Name is "com.myapp"
In MainActivity insert...

B4X:
Sub Process_Globals

   Dim PName as String : PName = "com.myapp"

End Sub

To use your Variable from Main Activity...

B4X:
Sub Fill_Label

   myLabel.Text = PName

End Sub

To use your Variable from any other Activity...

B4X:
Sub Fill_Label

   myLabel.Text = Main.PName

End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

udg

Expert
Licensed User
Longtime User
Maybe a function like could help:

B4X:
Sub GetPackageName As String
  Dim r As Reflector
  Return r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
End Sub
It uses the Reflection library.
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Thanks.yes i need to extract package name from manifest/apk running the code, i would like to protect my app from decompiling/recompiling and reskin

@holdemadvantage
How has it worked out? I assume you encrypted the string you were comparing against the package name returned.
 
Upvote 0
Top