Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback function is not called at all with no error #57

Closed
Mr-Slimon opened this issue May 12, 2021 · 7 comments
Closed

Callback function is not called at all with no error #57

Mr-Slimon opened this issue May 12, 2021 · 7 comments

Comments

@Mr-Slimon
Copy link

Mr-Slimon commented May 12, 2021

After messing around

I got the window to show - but now any button pressed is not calling the callbackfunction

In console all what I get is this

I/FLTFireMsgService( 3830): FlutterFirebaseMessagingBackgroundService started!
W/FLTFireMsgService( 3830): Attempted to start a duplicate background isolate. Returning...

D/SystemAlertWindowPlugin( 3830): onClickCallBackHandle 3292043634672398676
D/FLTFireMsgReceiver( 3830): broadcast received for message
D/SystemAlertWindowPlugin( 3830): Going to show System Alert Window
I/WindowServiceNew( 3830): Closing the overlay window
V/SystemAlertWindowPlugin( 3830): invoking callback for tag answer_button
V/SystemAlertWindowPlugin( 3830): Invoking on method channel
V/SystemAlertWindowPlugin( 3830): invoking callback for tag decline_button
V/SystemAlertWindowPlugin( 3830): Invoking on method channel

When i click the button i get the log of invoking callback and invoking on method as shown above

But I inserted print function before the case in the call back and even this is not giving any thing

void callBackFunction(String tag) {
  print('TAG RECORDER IS : $tag');
  switch (tag) {
    case "decline_button":
      print("Simple button has been clicked");
      break;
    case "focus_button":
      print("Focus button has been clicked");
      break;
    case "personal_btn":
      SystemAlertWindow.closeSystemWindow();

      break;
    default:
      print("OnClick event of $tag");
  }
}
@TylerMutai
Copy link

Hello ther Mr Silimon,
I would like to ask, did you put your callback function in the top level scope? Also, in the console window, you should see:

onClickCallBackHandle 3292043634672398676 followed by:
Starting callBackHandle...

Otherwise, you should see a message telling you the plugin isn't registered and therefore it will not invoke your callback

@Mr-Slimon
Copy link
Author

Mr-Slimon commented May 13, 2021

@TylerMutai

Ok, Now I am getting the error you mentioned

I/SystemAlertWindowPlugin(16721): Unable to start callBackHandle... as plugin is not registered

How I reached there, I was having build errors because I used the Application.java from Homepage , so i Modified it until i got t build, but what I done is I disabled it completely

after searching here, I found this issue which I guess is related
#14

So i knew the problem is in this file , the file worked for me is this :

First I created the file in this location:
android\app\src\main\kotlin\com\example\example\Application.java

then the code is the same on homepage with one line modified:

import android.os.Bundle;
  import in.jvapps.system_alert_window.SystemAlertWindowPlugin;
  import io.flutter.app.FlutterApplication;
  import io.flutter.plugin.common.PluginRegistry;
  import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.engine.FlutterEngine;

  public class Application extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
      @Override
      public void onCreate() {
          super.onCreate();
          //This is required as we are using background channel for dispatching click events
          SystemAlertWindowPlugin.setPluginRegistrant(this);
      }      @Override
      public void registerWith(PluginRegistry pluginRegistry) {
//THIS LINE I ADDED BEFORE PLUGINREGISTERY (FLUTTERENGINE) - AS I WAS GETTING ERROR : error: incompatible types:PluginRegistry cannot be converted to FlutterEngine
          GeneratedPluginRegistrant.registerWith((FlutterEngine)pluginRegistry);
      }

  }

Now it is building and I am getting this error of the plugin is not registered,

My callbackFunction is the first thing in my main.dart after importing the packages, so i don't know what i did wrong

I know that all the problems i have are because Application.java file

What is the correct way to install it because I can't seem to get the homepage code to work?

@TylerMutai
Copy link

Hey ther Mr Slimon.

The error you are getting there is because you haven't included the Application.java file as the main activity in your android manifest.xml
If you don't mind, could you post here your AndroidManifest.xml so that I could take a look.

@Mr-Slimon
Copy link
Author

Mr-Slimon commented May 13, 2021

@TylerMutai
OMG you are totally right, I forgot that I changed AndroidManifest.xml back to original yesterday
Because I was getting this error :

Unable to instantiate application com.example.example.Application: java.lang.ClassNotFoundException: Didn't find class "com.example.example.Application" on path

and actually I searched for how to do this correctly but I can't find something from flutter perspective to understand it.

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.example">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="حكايتي"
    android:icon="@mipmap/launcher_icon"
    android:allowBackup="false"
    android:fullBackupContent="false"
    android:usesCleartextTraffic="true"
    >
	<activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize"
        android:showOnLockScreen="true"
        android:screenOrientation="portrait"
 
        >
               
		<!-- Specifies an Android theme to apply to this Activity as soon as
             the Android process has started. This theme is visible to the user
             while the Flutter UI initializes. After that, this theme continues
             to determine the Window background behind the Flutter UI. -->
		<meta-data
          android:name="io.flutter.embedding.android.NormalTheme"
          android:resource="@style/NormalTheme"
          />
		<!-- Displays an Android View that continues showing the launch screen
             Drawable until Flutter paints its first frame, then this splash
             screen fades out. A splash screen is useful to avoid any visual
             gap between the end of Android's launch screen and the painting of
             Flutter's first frame. -->
		<meta-data
          android:name="io.flutter.embedding.android.SplashScreenDrawable"
          android:resource="@drawable/launch_background"
          />
		<intent-filter>
			<action android:name="android.intent.action.MAIN"/>
			<category android:name="android.intent.category.LAUNCHER"/>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
            
		</intent-filter>


	</activity>

     <activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>  
	<!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
	<meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-feature android:name="android.hardware.camera" />

I am very sorry , I don't have that much experience with Native android development - a lot of these concepts I searched the Internet for how to do it and that how I got to these results.

@TylerMutai
Copy link

Hey ther Mr. Silimon

In your Application.java file, I see that you have not defined your package, which is why you are getting the error.

I assume under your folder structure, your Application class is under android\app\src\main\kotlin\com\example\example\Application.java as you had mentioned earlier. So include this at the top of your Application.java file:

package com.example.example

It should now work

@TylerMutai
Copy link

TylerMutai commented May 13, 2021

Also remember to include the semi colon. Sorry. i.e.:

package com.example.example;

Then in your android manifest file, replace io.flutter.app.FlutterApplication with .Application under the <application> tag

@Mr-Slimon
Copy link
Author

Yep - it is working correctly now,

My fault was that in application tag I always added Application without the dot at the start

Thank you very much for your help, Happy coding 🥇

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

No branches or pull requests

2 participants