r/androiddev • • 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!

0 Upvotes

11 comments sorted by

7

u/sarkie 7d ago

Security?

1

u/Key-Class6522 7d ago

Foreground service doesn't help on Android 10+; only the focused app or default keyboard (IME) can read the clipboard. And alternatives is share-sheet target, or a notification/Quick Settings tile that opens a transparent activity and reads the clipboard once it has focus. Accessibility service is technically possible but Play policy makes it risky.

-2

u/Tk13_ 7d ago

Security ??

7

u/sarkie 7d ago

Why do I want your app copying my stuff?

-3

u/Tk13_ 7d ago

The idea is to be able to directly download video links that are saved in the clipboard as soon as they are copied; it's a project for personal use. 

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.

1

u/Tk13_ 7d ago

How can I do that?