0

I want to share link on facebook on long press of that link.I have intent to go to facebook or something on click of button but I want it on long press of link.Could anyone help me.

public class MainActivity extends Activity {
Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btn = (Button) findViewById(R.id.btn);
    btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

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

        }
    });
}

}

poojagupta
  • 982
  • 2
  • 12
  • 26
  • use `setOnLongClickListener()` after long click listener set ,to pass the data to facebook check this discussion on passing the data to facebook http://stackoverflow.com/a/13287074/2606342 – Akbarsha Feb 27 '14 at 07:34

2 Answers2

1

Just use button onLongclickListner event as follow

button.setOnLongClickListener(new OnLongClickListener() { 
        @Override
        public boolean onLongClick(View v) {
            // your code goes here
            return true;
        }
    });
InnocentKiller
  • 5,234
  • 7
  • 36
  • 84
0

use onlongclick dude :)

   btn = (Button) findViewById(R.id.btn);
        btn.setOnLongClickListener(new setOnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {

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

            }
        });
Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49