Android examples for android.content:Clipboard
has Text on Clipboard
import android.annotation.TargetApi; import android.content.ClipData; import android.content.ClipDescription; import android.content.ClipboardManager; import android.content.Context; import android.os.Build; public class Main{ public static boolean hasText(Context context) { ClipboardManager cm = (ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipDescription description = cm.getPrimaryClipDescription(); ClipData clipData = cm.getPrimaryClip(); return clipData != null && description != null && (description .hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)); } else {//from w w w .ja va 2 s .co m //noinspection deprecation return cm.hasText(); } } }