getCurrentApp static method
Gets the package name of the current foreground app. Requires Usage Stats permission on Android. Returns the package name as a String.
Implementation
static Future<String> getCurrentApp() async {
try {
final result = await _channel.invokeMethod<String>('getCurrentApp');
if (result == null) {
throw Exception('No foreground app detected');
}
return result;
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
throw Exception(
'Usage stats permission required. Please grant the permission in settings.');
} else {
throw Exception('Failed to get current app: ${e.message}');
}
}
}