Alternatively, if you just want to get the app package name of a running application, you can do this with calls to adb. You can try using appium-adb (https://github.com/appium/appium-adb), but I found it difficult to use. We created our own adb interface which works because we are only testing locally and not against selenium grids or the like.
To get the app package, you need to run the command ‘adb shell dumpsys window windows’ We specifically look for the two lines which contain either ‘mCurrentFocus’ or ‘mFocusedApp’ because the don’t always agree. Some heuristics are required to decide which one is correct.