Sneha Bansal
Sneha Bansal

Reputation: 941

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.

enter image description here

Please suggest me how can I achieve this

Upvotes: 0

Views: 82

Answers (3)

MineConsulting SRL
MineConsulting SRL

Reputation: 2340

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!

Upvotes: 1

Pratik Butani
Pratik Butani

Reputation: 62411

Write code on click of any View:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Your Subject Here");
intent.putExtra(Intent.EXTRA_TEXT, "Your Message Here...");
return intent;

Upvotes: 0

Naveen Tamrakar
Naveen Tamrakar

Reputation: 3339

hare is button click event use it

Intent intent = new Intent(android.content.Intent.ACTION_SEND); 
intent.setType("text/plain");
String shareBody = "Here is the share content body";
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(intent, "Share via"));

Upvotes: 0

Related Questions