Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of applications which can share data

This code shows default share dialog

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/html");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Message"));
startActivity(Intent.createChooser(sharingIntent,"Share using"));

share dialog

Question: Instead of showing the list of applications in the default system dialog, I want to get the list of applications and show them in my custom list.

like image 400
Himani Bansal Avatar asked Jun 08 '16 13:06

Himani Bansal


1 Answers

Use the PackageManager with the Intent to get the list of applications which can listen to the SEND intent. From the list of applications returned, get the details you would like to display, eg. the icon, name, etc. You would need the package name to launch the app when the user clicks on it.

PackageManager pm = getActivity().getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_SEND, null);
mainIntent.setType("text/plain");
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(mainIntent, 0); // returns all applications which can listen to the SEND Intent
for (ResolveInfo info : resolveInfos) {
    ApplicationInfo applicationInfo = info.activityInfo.applicationInfo;

    //get package name, icon and label from applicationInfo object and display it in your custom layout 

    //App icon = applicationInfo.loadIcon(pm);
    //App name  = applicationInfo.loadLabel(pm).toString();
    //App package name = applicationInfo.packageName;
}

After you have this set of application details, you can use this in the Adapter of your GridView and show the details.

like image 156
Swayam Avatar answered Oct 07 '22 02:10

Swayam