Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android queryIntentActivities always return empty list

Tags:

java

android

I'm trying to get a list of all applications that are capable of sending text messages.

I found several solutions on that suggest to use the PackageManager.

I think that the Intent to be used is ACTION_SEND, but when i run my code i always receive an empty List.

This is my code:

        Intent mainIntent = new Intent(Intent.ACTION_SEND, null);
        List<ResolveInfo> pkgAppsList = getApplicationContext().getPackageManager().queryIntentActivities( mainIntent, PackageManager.GET_RESOLVED_FILTER);
        int size = pkgAppsList.size();
        int i = 0;
        Log.i(TAG, "Size: " + size);
        for(ResolveInfo infos : pkgAppsList){
            String name = infos.activityInfo.applicationInfo.loadLabel(getPackageManager()).toString();
            Log.i(TAG, "name: " + name);
        }

Any idea?

like image 746
Ivan Avatar asked Jun 30 '14 21:06

Ivan


1 Answers

You haven't set the MIME type for the Intent. For example:

mainIntent.setType("text/plain");

That will produce results. However, be mindful that this won't exactly return "applications capable of sending text messages", rather those that can accept a text, not necessarily for the purpose of sending a message (as an example, the Google Translate app is capable of receving text).

like image 173
matiash Avatar answered Sep 16 '22 12:09

matiash