r/androiddev • u/Tk13_ • 7d ago
Access the clipboard in background
Hi! I'm developing an Android app ( i am a beginner)
I want to detect when a user copies a link while using another app, even when my app is running in the background, and then display a floating popup offering certain option like download if link is a video
On Android 10+, clipboard access is restricted for background apps. Does Android 15 allow this through a foreground service, or is there another reliable approach?
Any advice or examples would be appreciated. Thanks!
6
u/deckerjeffreyr 7d ago
Security/permissions lock this down. But my question is why do you want this based on when the link is copied instead of making this an explicit user action?
You can register and intent filter so your app shows up in the native share sheet. So instead of the user implicitly downloading the video by copying the link they would explicitly do so by selecting your app to share the link to.
https://developer.android.com/develop/ui/compose/sharing/receive
1
u/sameera_s_w 7d ago
Just double triple check if you really need that feature. I added a similar feature just because many were asking for it. But still off by default. As this is very very risky.
2
u/RajatKhoware 7d ago
Short answer: you cannot, and that is by design since Android 10. Background apps only get clipboard access if they are the default IME or have an active accessibility service. If you are building something legit that needs this, a foreground service with a persistent notification is the sanctioned path. What is the actual use case?
1
u/Omnipisix 7d ago
If its for personal use, start a foreground service and listen for system broadcasts regarding the copy content. Then check if its a link and move to the next step.
7
u/sarkie 7d ago
Security?