Page 1 of 1

Appname to pkgname

Posted: 26 Jun 2016 14:07
by newturn
Hi there,

is it possible to get the packagename from the appname (or even nickname)?

thanks

edit: i am using speech recognizing to say the app. for example "open dolphin". But i cant launch any app without the package name :(

Re: Appname to pkgname

Posted: 26 Jun 2016 19:18
by Martin
Hi,

There's no built-in feature to find the package name yet. You could use an action Map Values to map the names of a few apps to the package.
The next version of Automagic will provide an action called Init Variable Package Info that can list all apps installed on the system. It will provide label, icon and some technical information for each package. You still have to write a script to loop through the result to find the matching app.

Regards,
Martin

Re: Appname to pkgname

Posted: 26 Sep 2016 16:24
by yeyedroid
Hello, would you mind helping me in creating this loop that, starting from the app name (label), finds the corresponding package name and writes it to a variable?
Do i need to loop an Expression?

Re: Appname to pkgname

Posted: 26 Sep 2016 17:43
by Martin
Hi,

First you have to get the list of all apps with action Init Variables Package Info. Store the result in Variable package_info.

You can then use one of the following scripts to get the package name with the label:

Code: Select all

found_package=null;
keys=getMapKeys(package_info);
for (pn in keys)
{
  label=package_info[pn]["application_info"]["label"];
  if (label=="Automagic Premium")
  {
    found_package=pn;
    break;
  }
}
Alternative approach that might be faster if you want to look up multiple apps within the same flow execution. It creates a temporary map first and fills the map with the label of the apps as keys and the package name for the value.

Code: Select all

map=newMap();
keys=getMapKeys(package_info);
for (pn in keys)
{
  label=package_info[pn]["application_info"]["label"];
  addMapEntry(map, label, pn);
}
found_package=map["Automagic Premium"];
The package name will be stored in variable found_package. The variable might be null if no package matches.
Both scripts search for an app called "Automagic Premium".

Regards,
Martin

Re: Appname to pkgname

Posted: 04 Oct 2016 14:44
by yeyedroid
No need to say they work perfectly. Thanks.

I have another request (if I don't get you too much annoyed), searched a bit but have not found a solution.
Is it possible to check for "hidden" state of an app?
it is written in package-restrictions.xml and there is also a function to retrieve these information in Packagemanager.java (getApplicationHiddenSettingAsUser). You can find a lot of info about it here (don't know if it's something new to you) http://android.stackexchange.com/questi ... ity-crisis .
Is it possible to call that java function? Read here that you planned it viewtopic.php?f=4&t=5880

Re: Appname to pkgname

Posted: 04 Oct 2016 19:17
by Martin
Hi,

It seems that calling pm hide requires permission android.permission.MANAGE_USERS which is signature|privileged so I can't hide an app without the help of root.
Calling getApplicationHiddenSettingAsUser also requires this permission so it's not working from Automagic.

The java stuff is part of action Script. Search for java in the list of functions.
This post shows a simple example: http://automagic4android.com/forum/view ... 957#p14879

Action Init Variable Package Info does not return any information when a package is hidden. You could use this as a hint that it might be hidden.

Regards,
Martin

Re: Appname to pkgname

Posted: 06 Oct 2016 18:55
by yeyedroid
If it matters, I have root functions with Automagic.

For the script part I didn't have time to try as I'm not expert in coding and it might take lots of tests.

Fastest solution, as suggested by you, was to check the Enabled state for a package name: it would return exception if the package is in the hidden state.

Thanks again