替换剪贴板内容
Replacing clipboard content
如何检测创建一个识别特定字符串序列的程序并将其替换为我自己的字符串
例如,如果将以 "a" 开头的文本字符串复制到剪贴板,然后将其替换为 "newString"
public class MainActivity 扩展 AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView txtV = findViewById(R.id.text);
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clpData = ClipData.newPlainText("newText", txtV.getText());
clipboardManager.setPrimaryClip(clpData);
if (clipboardManager.getPrimaryClip().getItemAt(0).getText().toString().startsWith("H")) {
clipboardManager.setPrimaryClip(ClipData.newPlainText("newText", "newString"));
Toast.makeText(this, clipboardManager.getPrimaryClip().getItemAt(0).getText().toString(), Toast.LENGTH_LONG).show();
}
}
}
如何检测创建一个识别特定字符串序列的程序并将其替换为我自己的字符串
例如,如果将以 "a" 开头的文本字符串复制到剪贴板,然后将其替换为 "newString"
public class MainActivity 扩展 AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView txtV = findViewById(R.id.text);
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clpData = ClipData.newPlainText("newText", txtV.getText());
clipboardManager.setPrimaryClip(clpData);
if (clipboardManager.getPrimaryClip().getItemAt(0).getText().toString().startsWith("H")) {
clipboardManager.setPrimaryClip(ClipData.newPlainText("newText", "newString"));
Toast.makeText(this, clipboardManager.getPrimaryClip().getItemAt(0).getText().toString(), Toast.LENGTH_LONG).show();
}
}
}