How to customize the Onclick event of sharing intention in Android


How to customize the Android Share Intent for Facebook App. When I am using the share Intent, I am getting the following dialog.

But I am using Facebook sdk for post the image and text. And how to customize, when we click on Facebook icon in the above dialog it will navigate to my custom facebook dialog...

By using the below code u can get the list of social media networking apps list which are installed in your mobile.

Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
List activities = ShareList.this.getPackageManager().queryIntentActivities(sendIntent, 0);

Send this list to Adapter class:

ListView lv=(ListView)findViewById(;
final ShareAdapter adapter=new ShareAdapter(ShareList.this,activities.toArray());

Here is the Adapter class code:

public class ShareAdapter extends BaseAdapter {
Object[] items;
private LayoutInflater mInflater;
Context context;

public ShareAdapter(Context context, Object[] items) {
    this.mInflater = LayoutInflater.from(context);
    this.items = items;
    this.context = context;

public int getCount() {
    return items.length;

public Object getItem(int position) {
    return items[position];

public long getItemId(int position) {
    return position;

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.singleitem, null);
        holder = new ViewHolder(); = (TextView) convertView.findViewById(;
        holder.logo = (ImageView) convertView.findViewById(;
    } else {
        holder = (ViewHolder) convertView.getTag();
            .setText(((ResolveInfo) items[position]).activityInfo.applicationInfo

            .setImageDrawable(((ResolveInfo) items[position]).activityInfo.applicationInfo

    return convertView;

static class ViewHolder {

    TextView name;
    ImageView logo;

Handling the specific social media network in the listview using the below code:

lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            ResolveInfo info = (ResolveInfo) adapter.getItem(arg2);
            if(info.activityInfo.packageName.contains("facebook")) {
                new PostToFacebookDialog(context, body).show();
        //here u can write your own code to handle the particular social media networking apps.
                Toast.makeText(getApplicationContext(), "FaceBook", Toast.LENGTH_LONG).show();
            } else {
                Intent intent = new Intent(android.content.Intent.ACTION_SEND);
                intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
                intent.putExtra(Intent.EXTRA_TEXT, "body");