然後要用的地方呼叫它就行囉~
private void sendTextToOtherApp(String text) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, text); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, "Send text to...")); }
例如:
按一個按鈕時送出「This is my text to send.」
button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { sendTextToOtherApp("This is my text to send."); } });
沒有留言:
張貼留言