Java 如果共享未首先单击副本,则禁止单击该共享
我的代码如下所示:Java 如果共享未首先单击副本,则禁止单击该共享,java,android,Java,Android,我的代码如下所示: public boolean onOptionsItemSelected(MenuItem item){ switch (item.getItemId()) { case R.id.share: // send copy text Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sh
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case R.id.share:
// send copy text
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = returnedText.getText().toString();
String shareSub = "";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, shareSub);
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share using"));
Toast.makeText(getApplicationContext(),getString(R.string.send_text), Toast.LENGTH_SHORT).show();
break;
}
switch (item.getItemId()) {
case R.id.copy:
// copy text to clipboard
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(returnedText.getText());
Toast.makeText(getApplicationContext(),getString(R.string.copy_text), Toast.LENGTH_SHORT).show();
break;
}
return super.onOptionsItemSelected(item);
}
我需要什么?如果他们没有先单击副本,则禁止单击共享。如果他们没有先单击进行复制,应用程序会通知Toast消息他们必须复制文本,然后,当他们单击复制时,要共享的菜单项会有自己的功能 试试这个,不确定它是否有效
if (clipboardManager.hasPrimaryClip()){
// do what ever.
}else {
Toast.makeText(getApplicationContext(),"please click on copy first and try
again",Toast.LENGTH_LONG).show();
}