androidflutterflutter-pluginflutter-android

Is it possible to create public static variables in activity and access them from Flutter plugin in Android implementation?


The problem I have is only relevant for the Android version of the Flutter plugin, because context/activity is needed. I already made the implementation ActivityAware. Basically, the plugin needs some initialization to be usable by apps. The initialization values are different for different apps. My question is: Is it possible to put them in MainActivity and have them available for Flutter plugin's Android implementation? If it can be put in application, that is also good. If not possible in either, is there any other way to do this?

Currently to demonstrate that once initialized, the plugin can do its work, I hard-coded the values in the plugin's Android implementation. But if I try to access the values from MainActivity, it didn't work.


Solution

  • I was able to solve the problem by adding these values as meta data in AndroidManifest of the example app in the Flutter plugin. Then I accessed the data in the plugin's Android implementation by using PackageManager to get ApplicationInfo, and then through ApplicationInfo to get these values, like this: applicationInfo.metaData.getString("configInfo").