问题
I have this code for selecting a textView and copying to clipboard :
txt=(TextView)findViewById(R.id.textView1);
int startIndex = txt.getSelectionStart();
int endIndex = txt.getSelectionEnd();
final String stringYouExtracted = txt.getText().toString().substring(startIndex, endIndex);
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(stringYouExtracted);
I want put a button that when I press it , sends text that I have selected it in previous code , I have this code too :
btn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, stringYouExtracted);
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
});
Every thing is ok but when I press the button and choose other application for example viber ...... viber just opens and This Code Doesn't Sending Anything to viber .... It can just open viber ........... What should I do ????
来源:https://stackoverflow.com/questions/22756458/why-doesnt-this-code-send-anything-to-other-applications-it-just-opens-other