我使用以下代码通过共享菜单将文本从其他应用程序发送到我的应用程序,并在 EditText 中显示文本。
Intent receivedIntent = getIntent();
String receivedAction = receivedIntent.getAction();
String receivedType = receivedIntent.getType();
TextView txtView = (EditText) findViewById(R.id.edWord);
//if(receivedAction.equals(Intent.ACTION_SEND)){
if (Intent.ACTION_SEND.equals(receivedAction) && receivedType != null) {
if(receivedType.startsWith("text/")) {
String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT).toLowerCase();
if (receivedText != null)
{
txtView.setText(receivedText);
txtView.requestFocus();
ListView myList=(ListView) findViewById(R.id.lstWord);
myList.setFocusableInTouchMode(true);
myList.setSelection(0);
}
else
txtView.setText("");
}
}
一切正常,即发送的文本显示在我的 EditText 中(即edWord
在上面的代码中)。但问题是通过 Share 发送的文本有时包含无意义的元素或派生词,例如:"word
, word'
,word,
或looked
, books
, tomatoes
。
现在我想要的是格式化文本,使其在添加到 EditText 之前只包含真实单词或单词的基本形式。
我听说过approximate string matching
或者fuzzy searching
但我不知道如何将它应用到我的代码中。我想知道您是否可以给我一点帮助来解决上述问题,至少在格式化/剥离非单词元素方面。
提前致谢。