Skip to content

Add %app% and %package% filename placeholders for foreground app info#703

Merged
cvzi merged 12 commits intocvzi:mainfrom
Self-Perfection:claude/screenshot-app-info-QkoV0
Feb 15, 2026
Merged

Add %app% and %package% filename placeholders for foreground app info#703
cvzi merged 12 commits intocvzi:mainfrom
Self-Perfection:claude/screenshot-app-info-QkoV0

Conversation

@Self-Perfection
Copy link
Contributor

Allow users to include the foreground application name or package name in screenshot filenames. The accessibility service now tracks the foreground package unconditionally (not only when package filter is enabled), and formatFileName resolves the new placeholders via PackageManager.getApplicationLabel().

https://claude.ai/code/session_011TTQJFxqPwq3RD1tmtprvM

Not yet tested. I hope GitHub workflow will run after PR and will generate APK that I will be able to test.

Allow users to include the foreground application name or package name
in screenshot filenames. The accessibility service now tracks the
foreground package unconditionally (not only when package filter is
enabled), and formatFileName resolves the new placeholders via
PackageManager.getApplicationLabel().

https://claude.ai/code/session_011TTQJFxqPwq3RD1tmtprvM
Allow users to include the foreground application name or package name
in screenshot filenames. The accessibility service now tracks the
foreground package unconditionally (not only when package filter is
enabled), and formatFileName resolves the new placeholders via
PackageManager.getApplicationLabel().

https://claude.ai/code/session_011TTQJFxqPwq3RD1tmtprvM
@cvzi
Copy link
Owner

cvzi commented Feb 11, 2026

I ran the Github action on my repository, otherwise it won't run correctly. You can download the apk here at the bottom: https://github.com/cvzi/ScreenshotTile/actions/runs/21922996743

@Self-Perfection
Copy link
Contributor Author

Self-Perfection commented Feb 11, 2026

Dang. When called as digital assistant it always produces

%app% = "Screenshot Tile"
%package% = "com.github.cvzi.screenshottile"

regardless of actual app that was screenshotted.

When taking a screenshot via Digital Assistant, Quick Settings tile,
or floating button, the app's own window briefly comes to foreground.
This causes onAccessibilityEvent to overwrite lastPackageName with
the app's own package name before formatFileName() reads it.

Filter out the app's own package in onAccessibilityEvent so that
lastPackageName retains the actual foreground app.

https://claude.ai/code/session_011TTQJFxqPwq3RD1tmtprvM
When taking a screenshot via Digital Assistant, Quick Settings tile,
or floating button, the app's own window briefly comes to foreground.
This causes onAccessibilityEvent to overwrite lastPackageName with
the app's own package name before formatFileName() reads it.

Filter out the app's own package in onAccessibilityEvent so that
lastPackageName retains the actual foreground app.

https://claude.ai/code/session_011TTQJFxqPwq3RD1tmtprvM
@Self-Perfection
Copy link
Contributor Author

OK I added proprosed fix for this case

Trade-off: If the user takes a screenshot of ScreenshotTile itself (e.g. its settings screen), %app% and %package% will show the previous foreground app instead. This is an acceptable edge case since users rarely screenshot the app's own UI.

@cvzi
Copy link
Owner

cvzi commented Feb 11, 2026

Github action is running here: https://github.com/cvzi/ScreenshotTile/actions/runs/21924410958

@Self-Perfection
Copy link
Contributor Author

Self-Perfection commented Feb 11, 2026

Well, it got better.

%package% works perfectly when outside of Screenshot Tile.

But somehow %app% for most apps is not recognized and uses fallback to %package%.

Probably in this case %app% should not be included at all as an option?
Or maybe it's comment should mention, that this placeholder is not reliable?
What do you think?

For my use case %package% is enough.

%app% requires QUERY_ALL_PACKAGES to reliably resolve human-readable
app labels via PackageManager. Without it, Android 11+ package visibility
restrictions cause getApplicationInfo() to fail for most packages.
The code still supports %app% for users who add it manually, but it is
no longer advertised in the UI. Added a comment explaining the limitation.

https://claude.ai/code/session_011TTQJFxqPwq3RD1tmtprvM
@cvzi
Copy link
Owner

cvzi commented Feb 11, 2026

There should already be a function to load the appname of packages in the app, because there is a setting where the user can select to hide the floating button on selected apps. I don't know if that function is different to this or not, I think it should be in this file if you want to ask AI: app/src/main/java/com/github/cvzi/screenshottile/utils/PackagesRecyclerViewAdapter.kt

Anyway, I can take a closer look on the weekend.

cvzi and others added 7 commits February 13, 2026 23:27
* Add %app% and %package% filename placeholders for foreground app info

Allow users to include the foreground application name or package name
in screenshot filenames. The accessibility service now tracks the
foreground package unconditionally (not only when package filter is
enabled), and formatFileName resolves the new placeholders via
PackageManager.getApplicationLabel().

https://claude.ai/code/session_011TTQJFxqPwq3RD1tmtprvM

* Fix %app% and %package% always resolving to Screenshot Tile

When taking a screenshot via Digital Assistant, Quick Settings tile,
or floating button, the app's own window briefly comes to foreground.
This causes onAccessibilityEvent to overwrite lastPackageName with
the app's own package name before formatFileName() reads it.

Filter out the app's own package in onAccessibilityEvent so that
lastPackageName retains the actual foreground app.

https://claude.ai/code/session_011TTQJFxqPwq3RD1tmtprvM

* Remove %app% from filename placeholders documentation

%app% requires QUERY_ALL_PACKAGES to reliably resolve human-readable
app labels via PackageManager. Without it, Android 11+ package visibility
restrictions cause getApplicationInfo() to fail for most packages.
The code still supports %app% for users who add it manually, but it is
no longer advertised in the UI. Added a comment explaining the limitation.

https://claude.ai/code/session_011TTQJFxqPwq3RD1tmtprvM

* Revert "Remove %app% from filename placeholders documentation"

This reverts commit 22201e3.

* still run function even if event.packageName == packageName

* more robust label resolve for `%app%`

---------

Co-authored-by: Claude <noreply@anthropic.com>
@cvzi
Copy link
Owner

cvzi commented Feb 13, 2026

I have improved the %app% part. Can you check if this apk still works: https://github.com/cvzi/ScreenshotTile/actions/runs/22005724859

@Self-Perfection
Copy link
Contributor Author

Hi!

I tested it for a bit.

This build seems to be juuuust a little bit more reliable for extracting app name: it figured the name of https://f-droid.org/packages/com.gpl.rpg.AndorsTrail/ as "AndorsTrail", the previous version yielded fallback to com.gpl.rpg.AndorsTrail. But mostly this version seems to just drop first part of the package name. For instance, https://f-droid.org/packages/com.aurora.store/ becomes "aurora.store".

It seems that without QUERY_ALL_PACKAGES permission getting app name is not feasible.
See this comment (AI generated):
22201e3#diff-a256c68a04766529b1a1e3d3f020ae0d7dd456f33d681b7026486db6bbe2eb6cR459-R461

@cvzi cvzi merged commit fd274ac into cvzi:main Feb 15, 2026
4 checks passed
@cvzi
Copy link
Owner

cvzi commented Feb 15, 2026

Thanks!

@Self-Perfection
Copy link
Contributor Author

I noticed one more corner case.

If keyboard is shown AND screenshot is made via digital assistant, then %package% is identified as com.android.inputmethod.latin, and %app% becomes inputmethod.latin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants