androidgettextlong-click

how to get a word of view's of another application using longclick


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


Solution

  • 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 sample project demonstrates how to implement an ACTION_PROCESS_TEXT activity on Android 6.0.