0

I am working on a custom launcher application. I want to get information like "How many cameras, message or browser applications are installed on my device", that can be default or third party application? Please suggest me if have any idea for this.

Thanks in advance

Björn Kaiser
  • 9,882
  • 4
  • 37
  • 57
Sukesh
  • 313
  • 5
  • 15
  • Please punctuate your question, otherwise it's difficult to read. – Aleks G May 09 '12 at 11:25
  • you can try get applications' permission. for example: if app. have camera permission , it is a camera app. – Savas Adar May 09 '12 at 11:30
  • @SavasAdar: Just out of curiosity, I tried this on my phone - I got 17 apps with Camera pemissions - but only 1 of those is the Camera app. – Aleks G May 09 '12 at 11:32
  • Hi @SavasAdar Thanks for reply can u elaborate this i am not able to get this sorry for the trouble. – Sukesh May 09 '12 at 11:46

2 Answers2

3

You can use PackageManager to find out about the installed applications. However, you have no reliable way to determine which of those are "cameras" or "message" or "Browser".

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Yea you are right, but my scenario here is for example if there is an music icon on the screen, when the user selects the music icon, user should be able to see all the music application side by Like:Winamp,Real player.It may be a third party/default application. – Sukesh May 09 '12 at 11:33
  • @Sukesh: As I wrote, you have no reliable way to determine which of those are "cameras" or "message" or "Browser" or "music application". – CommonsWare May 09 '12 at 12:02
0

To get the info you're after, you'll need to use PackageManager class and whatever else it provides. For example, the following code retrieves the list of available "applications", that is Activities that are defined with Launch Intent in their respective AndroidManifest files - together with the .app files that contain them, launcher labels and icons, etc.

PackageManager pm = getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
String _label, _class, _src;
Drawable _icon;

for (ResolveInfo rInfo : pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)) {
    if (pm.getLaunchIntentForPackage(rInfo.activityInfo.packageName) == null) {
        continue;
    }
    _class = rInfo.activityInfo.packageName;
    _label = rInfo.activityInfo.loadLabel(pm).toString();
    _src = rInfo.activityInfo.applicationInfo.sourceDir;
    _icon = rInfo.activityInfo.loadIcon(pm);

    Log.d("PackageList", "label: " + _label + ", package: " + _class + ", sourceDir: " + _src + ", icon: " + (_icon == null ? "blank" : "present"));
}
Aleks G
  • 56,435
  • 29
  • 168
  • 265
  • hi this is good concept, this is a small code for getting all applications from the launcher, but how to filter these packages. i will give you basic idea about UI. I had a number of icons in the screen so if i press music icon it should show all the music applications which i installed in the device. – Sukesh May 09 '12 at 12:04
  • 1
    @Sukesh This is not possible, because there is no standard "type" attribute for applications. When an app is created, it can declare certain permission and you can try filtering by those, but it's very-very far from certain. As a feature, you'd be much better off allowing "groups" in your launcher, so that the users could group their apps the way they see fit. – Aleks G May 09 '12 at 12:20
  • Thank you for making some time and suggesting me. – Sukesh May 09 '12 at 12:42