Can UIAutomator be used in a production Android app?

I want to automate simple user interactions with a third-party app from my own Android app. This requires inspecting and interacting with other apps. From my research, UIAutomator seems like the most general-purpose tool for this. Are there any restrictions or issues that would prevent me from using UIAutomator in an app released on the Google Play Store?

From my experience, UIAutomator isn’t really designed for production apps distributed on the Google Play Store, especially if you’re looking to interact with other apps. It’s primarily a testing tool for UI automation, meant for use within the context of instrumentation tests, not runtime interaction between third-party apps.

UIAutomator needs a special permission, INJECT_EVENTS, which is a signature-level permission, and regular apps from the Play Store can’t obtain this permission. Plus, trying to use it in production could go against Google’s Play policies, since injecting events into other apps is considered invasive. So, while androiduiautomator works great in test environments, it’s not a good fit for production use.

Yeah, I’d say think of androiduiautomator more as a testing tool than something you’d use for app logic. It’s built to automate your own app or the system UI in tests, and it runs under instrumentation, not as a standalone user app. If you try to bundle it in a production app, it won’t have the necessary permissions to click buttons or interact with other apps’ UIs. It simply won’t work in that case.

From what I’ve seen, if you want to interact with other apps programmatically in a production environment, there are a few options you could explore:

  1. Accessibility Services: You can create an accessibility service within your app that can observe and interact with other apps, though the user would have to manually enable the service. This is officially supported for automation in specific use cases, like accessibility.
  2. Deep Linking / Intents: Instead of trying to automate the UI, you can use public intents or deep links exposed by the target app. This approach is safe for production apps, doesn’t require special permissions, and works well in real-world scenarios.
  3. Custom SDK/Collaboration: If you control both apps, you can expose an API or SDK for automation tasks, which avoids any UI injection altogether.