2

do you know how to get acces to getPackageManager() (for java) in react-native please? I searched everywhere but I only found some errors with getPackageManager()... I need this to know if my app has been downloaded from the Play Store or by other method. (I can't say Hi at the beginning of my post, I'm polite normaly:))

Thanks

RatFou
  • 33
  • 1
  • 5
  • Possible duplicate of [Can't find getPackageManager() method in android](http://stackoverflow.com/questions/22396382/cant-find-getpackagemanager-method-in-android) – Kerumen Dec 04 '16 at 13:00
  • It's for android in java, I need it in react-native – RatFou Dec 04 '16 at 18:11

2 Answers2

2

You can use the react native application context and get the package manager from there.

PackageManager manager = reactContext.getPackageManager();

or just get it from the current activity

Activity currentActivity = getCurrentActivity();
PackageManager manager = currentActivity.getPackageManager();
Sven
  • 124
  • 4
1

Yes, you can use the react native application context and get the package manager. However, I used the getReactApplicationContext method to get the context. So the answer becomes:

PackageManager pm = getReactApplicationContext().getPackageManager();
Raunaqss
  • 1,265
  • 12
  • 17