英文:
Can I get the surrounding text from selected text in Android?
问题
I would like to develop a translator application on Android, which translates not only the selected (ACTION_PROCESS_TEXT-ed) text but also the whole sentence.
For example: I am reading an article in a browser in a foreign language, and I am reading the following sentence:
Ich liebe dich, du liebst mich nicht.
I select the word "liebe", then I select my application from the context menu (In the picture, Copy with clipnote is shown, imagine here the name of my application) then I want to translate not only the word "liebe" but also the whole sentence. (So the string Ich liebe dich, du liebst mich nicht.)
Is it possible?
I am expecting to get the surrounding text of the selected world.
英文:
I would like to develop a translator application on Android, which translates not only the selected (ACTION_PROCESS_TEXT-ed) text but also the whole sentence.
For example: I am reading an article in a browser in a foreign language, and I am reading the following sentence:
Ich liebe dich, du liebst mich nicht.
I select the word "liebe", then I select my application from the context menu (In the picture, Copy with clipnote is shown, imagine here the name of my application) then I want to translate not only the word "liebe" but also the whole sentence. (So the string Ich liebe dich, du liebst mich nicht.)
Is it possible?
I am expecting to get the surrounding text of the selected world.
答案1
得分: 1
"Is it possible?"
不太可能。ACTION_PROCESS_TEXT
明显不支持应用程序获取超出所选文本的任意数量文本,这是出于明显的隐私和安全原因。
我无法排除通过 AccessibilityService
来实现你所寻求的可能性。但在你追求这条路之前,你可能希望与合格的法律顾问讨论你的计划,他们可以就你所在地的法律和你首选的应用分发平台的条款给你提供建议。
英文:
> Is it possible?
Not really. ACTION_PROCESS_TEXT
definitely does not support apps obtaining arbitrary amounts of text beyond what was selected, for obvious privacy and security reasons.
I cannot rule out the possibility of creating what you are seeking via an AccessibilityService
. However, before you go down that path, you may wish to discuss your plans with qualified legal counsel, who can advise you regarding the laws in your area and the terms of your preferred app distribution platform(s).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论