0

Im using this example to get the package name of a target app. I trying to create a service in background that when user open gmail for example, I could get the text from the class android.widget.EditText.

I suppose that the service has to be active always checking if the user open the target app, then when user open this target app, my service has to get the text of the class EditText, if the field is focused.

There is no example on internet to do this. Can you explain how to get this done, please?

Ivan
  • 13
  • 1
  • 5

1 Answers1

0

Do you want to get other application's package name? Your example gets your application's name. That is different.

If you want to get other application's name, you need the android.permission.GET_TASKS permission, So that may be why you cannot find a related example.

As of LOLLIPOP, this method is no longer available to third party applications: the introduction of document-centric recents means it can leak personal information to the caller. For backwards compatibility, it will still return a small subset of its data: at least the caller's own tasks (though see getAppTasks() for the correct supported way to retrieve that information), and possibly some other tasks such as home that are known to not be sensitive.

please see this thread:GET_TASKS Permission Deprecated, So you cannot found related example.

If you want to get the current running application's name, you can use the ADB command to get it

adb shell dumpsys window | findstr mCurrentFocus

Here is running screemshot when I open chrome.

enter image description here

Leon
  • 8,404
  • 2
  • 9
  • 52
  • About the permissions, then what could be a workaround this? – Ivan Aug 12 '20 at 20:27
  • It is real to add an option with a new function to the menu "PASTE SELECT ALL" when user holds a finger over a textedit of any other app? Or maybe a service that when user touch 3 times over the textedit of any app, this will execute some code? – Ivan Aug 12 '20 at 20:35
  • `About the permissions, then what could be a workaround this?` No, If you want to add `"PASTE SELECT ALL"` to menu in your app, youcan refer to this thread https://medium.com/androiddevelopers/custom-text-selection-actions-with-action-process-text-191f792d2999 – Leon Aug 13 '20 at 01:25
  • Very helpfull, so my goal has to be a public API, right? For example, creating a local notification that shows up when user open chrome and try to edit a text (when keyboard shows up) ? – Ivan Aug 14 '20 at 01:59