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"));
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With