X-SLAYER / flutter_accessibility_service

Flutter plugin for interacting with Accessibility Service in Android.
https://pub.dev/packages/flutter_accessibility_service
MIT License
33 stars 24 forks source link

W/FlutterJNI(23350): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: x-slayer/accessibility_event. #29

Open adityaiueo opened 6 months ago

adityaiueo commented 6 months ago

Issue Description

Problem: I am attempting to identify the currently active application using the Flutter Accessibility Service. After following the instructions provided on the package’s pub.dev page, I utilized event.packageName to achieve this. However, upon implementing the code in my main.dart, I encountered the following error:

W/FlutterJNI(23350): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: x-slayer/accessibility_event. Response ID: 131

This error occurs after my application is closed, and persists even when the application is reopened.

Steps to Reproduce:

  1. Install the flutter_accessibility_service package and follow the instructions in the README.

  2. I'm just adding the following damn code to the MyApp class in main.dart:

    
    StreamSubscription<AccessibilityEvent>? _subscription;
    List<AccessibilityEvent?> events = [];
    String currentApp = '';
    
    String getCurrentApp() {
     if (_subscription?.isPaused ?? false) {
       _subscription?.resume();
       return '';
     }
     _subscription = FlutterAccessibilityService.accessStream.listen((event) async {
       setState(() {
         currentApp = event.packageName!;
       });
       log("current event : $currentApp");
     });
     return currentApp;
    }
  3. Run the application on an emulator and enable accessibility permissions.

  4. Close the app.

Expected Behavior: The getCurrentApp() function should log the package name in the terminal, but it does not execute as expected, and no package name is logged.

Actual Behavior: The error message is displayed, and the expected behavior does not occur.

any idea how to fix it? your help is wanted! @X-SLAYER @fahimfoysal2 @avisihag Thank You