在主activity onResume中执行
public void getInfo(final Context context) {
ClipboardManager clipboard = (ClipboardManager)context.getSystemService(CLIPBOARD_SERVICE);
//无数据时直接返回
if (!clipboard.hasPrimaryClip()) {
return;
}
//如果是文本信息
if (clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
ClipData cdText = clipboard.getPrimaryClip();
ClipData.Item item = cdText.getItemAt(0);
//此处是TEXT文本信息
if (item.getText() != null) {
String str = item.getText().toString();
String key = "*";
final int first = str.indexOf(key);
if (first >= 0) {
String new1 = str.substring(first + 1);
int tow = new1.indexOf(key);
if (tow >= 0) {
String new2 = new1.substring(0, tow);
System.out.print(new2);
if (new2.length() == 8) {
//new2即为口令字符串
}
}
}
}
}
}
网友评论