Skip to content

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Oct 12, 2025

Android parity for screenshotcaptured using Android 14 registerScreenCaptureCallback: https://developer.android.com/about/versions/14/features/screenshot-detection#java

Changes:

  • add Android parity for screenshotcaptured event
  • move Ti.App.iOS.screenshotcaptured to Ti.App.screenshotcaptured
  • add deprecation message for Ti.App.iOS.screenshotcaptured
  • Android: add window base screenshotcaptured event

Test:

var win = Ti.UI.createWindow({
	id: "win1",
	backgroundColor: "#fff"
});
var btn = Ti.UI.createButton({
	top: 40,
	title: "open"
})
btn.addEventListener("click", function() {
	var win2 = Ti.UI.createWindow({
		backgroundColor: "#fff",
		id: "win2"
	})
	var lbl2 = Ti.UI.createLabel({
		color: "#000",
		text: "only app even is still fired, see log"
	});
	win2.open();
	win2.add(lbl2);
})
var lbl = Ti.UI.createLabel({
	color: "#000",
	text: ""
});
win.add([btn, lbl]);
win.open();

// iOS parity
Ti.App.addEventListener("screenshotcaptured", function() {
	console.log("Ti.App event");
	lbl.text += "Ti.App event\n";
})
Ti.App.iOS.addEventListener("screenshotcaptured", function() {
	console.log("Ti.App.iOS event");
	lbl.text += "Ti.App.iOS event\n";
})

// window level - Android only
win.addEventListener("screenshotcaptured", function(e) {
	console.log("win event");
	lbl.text += "win " + e.source.id + " event\n";
})
  • and add <uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE"/> to your tiapp.xml
  • Run the app and take a screenshot.
  • log and label will show that two events are fired
  • click the open button to open a new window
  • take a screenshot
  • only the app event is fired, no window event

@prashantsaini1
Copy link
Contributor

@m1ga

  1. We are firing Ti.App level events generated from per-activity level, it would be safe to test that the screen-capture callback is always invoked by the Android OS only when that activity is visible.
  2. After the above point, we should also let users know that which activity/ti-window this event is being fired for.
    • e.g. A window where some private content is shown and user takes screenshot, the app may only want to handle that specific use-case, without worrying about rest of the screens.
    • It can be achieved by firing ti-window level event also, and keeping the Ti.App event as is. So this covers both use cases - if app just needs to know app-wide, it'll be through Ti.App, and if required for only specific window, then using the window's screenshot event. Just need to add this info in docs?

@m1ga
Copy link
Contributor Author

m1ga commented Oct 14, 2025

Thanks for the comments!

I have to check how the iOS event is fired. I've added the window event and changed the example.
Currently it behaves like this:

  • Ti.App event: will fire in all windows
  • win event: will only fire if the window is open, if you open the 2nd window it won't fire in the 1st window

Update: the Ti.App event behaves the same now on both platforms. Android will also have the per Window event.

@m1ga m1ga marked this pull request as ready for review October 14, 2025 16:57
Copy link
Contributor

@prashantsaini1 prashantsaini1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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.

2 participants