is it possible to get a word of every text or passage in a phone(e.g from other applications) using longclick? for example i want to create a word translator and it must be able to get every word in every where in a phone for translating(an android app like babylon translator). i know that there is some solve like select a word on a tap in TextView/EditText ... but these answers coudn't use for views of another applications. thanks for every answer and sorry for bad English
is it possible to get a word of every text or passage in a phone(e.g from other applications) using longclick?
No.
The closest thing that exists is ACTION_PROCESS_TEXT
in Android 6.0+. If you have an activity with the right <intent-filter>
, you will be included in the floating action mode that allows the user to cut, copy, paste, and so on:
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
If the user chooses your activity, you will get the highlighted text as an Intent
extra.
However:
This is only for Android 6.0+, which at the moment has approximately 0.0% of the Android device market. That will improve over time, of course.
The user has to opt into this, by tapping on the entry for your activity in the floating action mode. Just because the user happens to highlight some text does not automatically give you that text.
This sample project demonstrates how to implement an ACTION_PROCESS_TEXT
activity on Android 6.0.