title: Android - How to get any application version by package name
body: <p>I want to do some stuff in my own android application where I need to check some system applications versions before. (System &amp; 3rd party apps) </p>
  
  <p>How to do it in Android Studio?</p>
  
  <p>In ADB I can dump it by:</p>
  
  <pre><code>adb shell dumpsys package com.samsung.android.calendar | grep versionName
  </code></pre>
  
  <p>but how to do it in code?</p>
  
  <p>note: it's not duplicated question, none of solutions provided in comments works for me. I want to check ANY app version, not MY app</p>