Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: how to get your Android app version?



Permlink Replies: 5 - Last Post: Jan 26, 2018 10:04 PM Last Post By: Ranksfery Fanerty
Dagmara Niedzwi...

Posts: 13
Registered: 11/15/15
how to get your Android app version?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2017 7:14 AM
Hi all

I want to get version number of my app. I am using code:

JPackageInfo* pInfo;
AnsiString version;
pInfo = SharedActivityContext()->getPackageManager()->getPackageInfo(SharedActivityContext()->getPackageName(), 0);
version = JStringToString(pInfo->versionName);

I am not able to pass 4th line. Errors:
First chance exception at $A191CE46. Exception class Segmentation fault (11).
First chance exception at $A191CE46. Exception class EAccessViolation with message 'Access violation at address A191CE46, accessing address 000000F0'.

What am I doing wrong?

Thanks for any advice!
Dagmara
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: how to get your Android app version?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 13, 2017 11:05 AM   in response to: Dagmara Niedzwi... in response to: Dagmara Niedzwi...
Dagmara wrote:

What am I doing wrong?

You should be using the _di_JPackageInfo smart pointer wrapper instead of
a raw JPackageInfo* pointer:

_di_JPackageInfo pInfo = SharedActivityContext()->getPackageManager()->getPackageInfo(SharedActivityContext()->getPackageName(), 
0);


Also, why are you using AnsiString? JStringToString() returns a UnicodeString.

--
Remy Lebeau (TeamB)
Dagmara Niedzwi...

Posts: 13
Registered: 11/15/15
Re: how to get your Android app version?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 14, 2017 12:30 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
You should be using the _di_JPackageInfo smart pointer wrapper instead of
a raw JPackageInfo* pointer:

Thanks Remy! It works.


Also, why are you using AnsiString? JStringToString() returns a UnicodeString.
This is my habit, I am usually using AnsiString in my code. Thanks!
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: how to get your Android app version?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 14, 2017 10:27 AM   in response to: Dagmara Niedzwi... in response to: Dagmara Niedzwi...
Dagmara wrote:

Also, why are you using AnsiString?
This is my habit, I am usually using AnsiString in my code.

Then you are invoking a lot of unnecessary string conversions at runtime,
and which can lead to data loss/corruption. The entire RTL, FMX, and Android
APIs are all Unicode-based, so use UnicodeString instead. Or at least the
System::String typedef.

--
Remy Lebeau (TeamB)
Dagmara Niedzwi...

Posts: 13
Registered: 11/15/15
Re: how to get your Android app version?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 15, 2017 1:14 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Then you are invoking a lot of unnecessary string conversions at runtime,
and which can lead to data loss/corruption. The entire RTL, FMX, and Android
APIs are all Unicode-based, so use UnicodeString instead. Or at least the
System::String typedef.

Thanks for advice!
Ranksfery Fanerty

Posts: 1
Registered: 2/23/18
Re: how to get your Android app version?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 23, 2018 2:19 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Dagmara wrote:

Also, why are you using AnsiString?
This is my habit, I am usually using AnsiString in my code.

Then you are invoking a lot of unnecessary string conversions at runtime,
and which can lead to data loss/corruption. The entire RTL, FMX, and Android
APIs are all Unicode-based, so use UnicodeString instead. Or at least the
System::String typedef.

--
Remy Lebeau (TeamB)
I used to use the AnsiString , but now i have switched Android manager ,which is the best way to manage and backup data on computer for Android phone

Edited by: Ranksfery Fanerty on Jan 26, 2018 10:01 PM

Edited by: Ranksfery Fanerty on Jan 26, 2018 10:03 PM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02