davidmartos96 / sqflite_sqlcipher

SQLite flutter plugin
BSD 2-Clause "Simplified" License
102 stars 46 forks source link

Integration with onBackgroundMessage FCM #21

Closed fauzy6493 closed 4 years ago

fauzy6493 commented 4 years ago

Hi David,

I need integration with firebase_messaging onBackgroundMessage handler.

The code successfully run when apps is on foreground, but when apps go to background and retrieve some data using onBackgroundMessage handler. Error is coming like this:

MissingPluginException(No implementation found for method getDatabasesPath on channel com.davidmartos96.sqflite_sqlcipher)

Another plugin i can resolved by register plugin in application level (android):


public class MyApplication extends FlutterApplication implements PluginRegistrantCallback {

    @Override
    public void onCreate() {
        super.onCreate();
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
    }

    @Override
    public void registerWith(PluginRegistry registry) {
        BackgroundLocationPlugin.registerWith(registry.registrarFor("com.almoullim.background_location.BackgroundLocationPlugin"));
        FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
        SharedPreferencesPlugin.registerWith(registry.registrarFor("io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"));
    }

}

But when i try same way to register: SqfliteSqlCipherPlugin.registerWith(registry.registrarFor("com.davidmartos96.sqflite_sqlcipher.SqfliteSqlCipherPlugin"));

is not solved when i receive onBackgroundMessage handler.

How can i use plugin in backgroundmode?

fauzy6493 commented 4 years ago

Solved already.

  1. Registerring plugin to MyApplication.java
    
    @Override
    public void registerWith(PluginRegistry registry) {
        BackgroundLocationPlugin.registerWith(registry.registrarFor("com.almoullim.background_location.BackgroundLocationPlugin"));
        FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
        SharedPreferencesPlugin.registerWith(registry.registrarFor("io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"));
    SqfliteSqlCipherPlugin.registerWith(registry.registrarFor("com.davidmartos96.sqflite_sqlcipher.SqfliteSqlCipherPlugin"));
    }


2. Restart Debug. Hot reload is not enough to refresh register plugin.

I close this issue. Thanks David.
mishatron commented 3 years ago

This issue should be reopened, because it is too old. I use flutter 2.0.5 and I do not know how to solve it!!! Please, help

davidmartos96 commented 3 years ago

@mishatron I'm sorry, but I've never used Firebase FCM, so I don't know very much about it. Could you share a simple project on github that reproduces the error? Also, in case your Flutter project was created long ago, this may be necessary https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects

mishatron commented 3 years ago

I did some tries and detected that problem is gone if I remove shrinkResources true from build.gradle on android. why?

davidmartos96 commented 3 years ago

@mishatron I'm not sure how that could be related. If you have a simple example app I wouldn't mind taking a look

aleslanik2 commented 2 years ago

Hi, i don't know why, but on very old Android devices i have this issue (FCM and Sqlite... libraries) . My solution is manually registration plugin in FlutterActivity

public class MainActivity extends FlutterActivity {

    @Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        super.configureFlutterEngine(flutterEngine);

        if(!flutterEngine.getPlugins().has(SqflitePlugin.class)){
            flutterEngine.getPlugins().add(new SqflitePlugin());
        }

        if(!flutterEngine.getPlugins().has(SqfliteSqlCipherPlugin.class)){
            flutterEngine.getPlugins().add(new SqfliteSqlCipherPlugin());
        }

    }

}