Getting the package name for an app

1,327 views
Skip to first unread message

UncleMike

unread,
Mar 5, 2013, 10:21:11 AM3/5/13
to tas...@googlegroups.com
I'm working on publishing a revised version of my notification reminder profiles on the Wiki, and have decided that things need to be a little more user friendly.  Although the notifications the profiles monitor are stock Google apps, and should have a should have the same package name on (almost) all devices, my (now dated) experience tells me that this isn't always the case; and varying package names will cause the profiles to not work as expected.  Plus, being able to determine the package name will make it much easier for users to add other applications to the list of those being monitored.  The reason I need the package name is that I'm using a script command dumpsys notification to determine which notifications are present in the notification bar, which I then use to decide whether notification reminders should sound/vibrate.

I've looked at various events, actions and variables that might tell me the package name, but none seem to do/provide what I want.  Specifically, I've looked at:

The Notification event - I was hoping that %evtprm1 would give the package name, but instead if gives the app label (i.e. I want "com.google.android.gm" and it gives "Gmail")
The Test action, using a Type of Package Name - given the package name, this returns the app label

If I could either get the Notification event to provide the package name, or something to do the opposite of what the Test Package Name action does, that would be perfect (I think).  Any suggestions?

GermainZ

unread,
Mar 5, 2013, 11:02:56 AM3/5/13
to tas...@googlegroups.com
/data/system/packages.xml, /data/system/packages.list and dumpsys package all give a lot of information. Unfortunately, the app's label is mentioned, so there will be some guessing involved if you want to match the label with the package's name.
If you just want to check the package's name with a predefined list of packages, it's fine.

TomL

unread,
Mar 5, 2013, 11:46:00 AM3/5/13
to tas...@googlegroups.com
Try this using sqlite3

sqlite3 /data/data/com.android.vending/databases/localappstate.db ".schema"

sqlite3 -header /data/data/com.android.vending/databases/localappstate.db "select package_name, title from appstate"


I agree that it would be nice if there was a simplier way to query this.

Tom

GermainZ

unread,
Mar 5, 2013, 11:50:01 AM3/5/13
to tas...@googlegroups.com
That is very likely to fail. AFAIK, it only shows apps installed through play store and a fresh ROM apparently clears the list (it then slowly regenerates; every update adds the package to the list).

On my ROM (newly flashed), there are only two rows.

TomL

unread,
Mar 5, 2013, 11:54:21 AM3/5/13
to tas...@googlegroups.com
Yeah, it's just a local cache.  Still, it's the closest thing I've found to a simple lookup table between package name and app title.

Otherwise, you'd have to dump the list of package names (from pm list packages, for instance) and then feed it one by one to Tasker's "Test Package Name" in order to get the app title.

Tom

GermainZ

unread,
Mar 5, 2013, 1:09:55 PM3/5/13
to tas...@googlegroups.com
And I was parsing packages.list....
Thanks for the tip, this make it much easier :P

pm list packages | sed "s/package://g"

UncleMike

unread,
Mar 5, 2013, 10:03:19 PM3/5/13
to tas...@googlegroups.com
Since my goal is to determine the package name for the Owner Application in a Notification event, I realized I can get a comma-delimited "short list" of packages that have active notifications with the following shell command:

dumpsys notification | grep pkg\= | sed -e s/.*pkg\=// -e s/[[:space:]].*// | sort | uniq | sed ':a;N;$!ba;s/\n/,/g

I can then use the Test Package Name action to see which package corresponds to the app label in the %evtprm1 variable within the task.  While implementing this approach I discovered an issue with the For action not treating the comma-delimited list as separate items.  Once that gets worked out I'll hopefully finish implementing this approach.

GermainZ

unread,
Mar 6, 2013, 4:19:35 AM3/6/13
to tas...@googlegroups.com
Make it an array and use %ARRAY() in the For loop instead.

Daniel Dur

unread,
Mar 6, 2013, 6:09:16 AM3/6/13
to tas...@googlegroups.com
Sorry to highjack the thread... 
Is there a possibility to get this information from the apk itself? While reading this thread I was thinking that I could make a task to rename all the apk's in a directory based on their internally stored name and version.

Thanks
Message has been deleted

UncleMike

unread,
Mar 6, 2013, 7:56:21 AM3/6/13
to tas...@googlegroups.com
I tried that and got the same result, but later found a mistake that made it behave the same way.  Correctly implemented on my end, it works fine.  Thanks.

TomL

unread,
Mar 6, 2013, 9:39:50 AM3/6/13
to tas...@googlegroups.com
You can unzip the apk file into a folder structure.  From there, you can poke around the AndroidManifest.xml file or the resources.arsc file.  The app title is in there somewhere, but both files are in binary format, and I haven't found a simple commandline tool that runs in Android to parse them.

Tom
Reply all
Reply to author
Forward
0 new messages