views:

222

answers:

1

Hi I want to publish my application (ABC). Its an audiobook file(just for example.) wrapped as apk. When the user install this application it needs to check whether another application (XYZ) already installed or not. If not let the user know they have to install the application XYZ first before installing ABC.

Thanks in advance

Rajesh

+2  A: 

If you know the package name of the application you are looking for you can use the PackageManager to test for the existence of an application.

try{
     ApplicationInfo info = getPackageManager()
                             .getApplicationInfo("com.myproject", 0 );
     //-- application exists
    } catch( PackageManager.NameNotFoundException e ){
     //-- application doesn't exist
}
jeremynealbrown
I don't think you can do this "on install" though. You will need to do it the first time you run the app most likely.
mbaird
right... I don't think that it is possible to run this code on install. That said, what action can you take during install process? Would it be better to check for the existence of another application the first time someone actually ran your app?
jeremynealbrown
"That said, what action can you take during install process?" Nothing -- you do not get control under the user first launches your app. "Would it be better to check for the existence of another application the first time someone actually ran your app?" No choice -- that's the only real option. I've argued for a dependency system for APKs to deal with this situation, and the response has been...underwhelming.
CommonsWare
Thanks for chiming in CommonsWare. I like the answers that spawn questions that spawn answers. :)
jeremynealbrown