Q:

Need to share text via applications

I need to share text from my applications via other social applications.I have got a piece of code that is working fine but it shows apps list in dialogue box:

And I want same feature in this way.May be I need to create views dynamically as per application installed in device.

Please suggest me how can I achieve this 

A:

This code will let you find all the apps available for the specified intent:
public static ArrayList<Availables> getAvailableAppsForIntent(Intent intent, Context context) {
    ArrayList<Availables> availables = new ArrayList<Availables>();

    PackageManager manager = context.getPackageManager();
    List<ResolveInfo> infos = manager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);

    for(ResolveInfo info : infos) {
        ActivityInfo activityInfo = info.activityInfo;
        IntentFilter filter = info.filter;
        if (filter != null && filter.hasAction(intent.getAction())) {

            // This activity resolves my Intent with the filter I'm looking for
            String activityPackageName = activityInfo.packageName;
            String activityName = activityInfo.loadLabel(manager).toString();
            String activityFullName = activityInfo.name;
            Drawable icon = activityInfo.loadIcon(manager);
            Availables available = new Availables(activityName, activityFullName, activityPackageName, icon);
            available.setForIntent(intent);
            availables.add(available);
        }
    }

    return availables;
}

Availables is just a class i created to store all the informations about the apps but you can manage it however you want.
then you can start the app this way:
    Intent intent = available.getForIntent();
    intent.setPackage(available.getAppPackage());
    context.startActivity(intent);

Hope it helps!

