How to Customize the Share Intent Onclick Event in Android

Mr. N.V.Rao

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

Share Intent 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...

Venu

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);
sendIntent.setType("text/plain");
List activities = ShareList.this.getPackageManager().queryIntentActivities(sendIntent, 0);

Send this list to Adapter class:

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

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();
        holder.name = (TextView) convertView.findViewById(R.id.textView1);
        holder.logo = (ImageView) convertView.findViewById(R.id.imageView1);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.name
            .setText(((ResolveInfo) items[position]).activityInfo.applicationInfo
                    .loadLabel(context.getPackageManager()).toString());

    holder.logo
            .setImageDrawable(((ResolveInfo) items[position]).activityInfo.applicationInfo
                    .loadIcon(context.getPackageManager()));

    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() {

        @Override
        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.setClassName(info.activityInfo.packageName, info.activityInfo.name);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
                intent.putExtra(Intent.EXTRA_TEXT, "body");
                ((Activity)ShareList.this).startActivity(intent);
            }

        }
    });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to Customize the Share Intent Onclick Event in Android

From Dev

Customize Share Intent Android

From Dev

How to customize share intent in Android (which is possible)

From Dev

How to customize share intent?

From Dev

Share Intent: customize layout

From Dev

Customize UI of Share Intent

From Dev

How to share an android application with intent

From Dev

How to confirm Android Share Intent is successful or complete

From Dev

How to create a "general" share intent in android ?

From Dev

How to create share intent for iOS like Android?

From Dev

How to filter facebook share intent in android?

From Dev

How to Share Image+Text using Share Intent in android

From Dev

Android Share Intent Completed

From Dev

Android share intent issue

From Dev

How to share text into facebook using default android sharing(intent)?

From Dev

Android: How to share image with text on facebook via intent?

From Dev

How to send apk using share intent programatically in android

From Dev

Android: How to share image with text on facebook via intent?

From Dev

share image with URL android share intent

From Dev

Setting font in share intent android

From Dev

Android share intent from intentservice

From Dev

Android Photos App Share Intent

From Dev

Android share Intent with clickable link

From Dev

Trying to share image with intent Android

From Dev

Setting font in share intent android

From Dev

Android share intent for multiple jokes

From Dev

How to create an Observable from OnClick Event Android?

From Dev

Customize Android Intent.ACTION_SEND

From Dev

Android Share Content OnClick Listview