Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我编写颤振插件时,如何获取android.app.Application对象_Android_Flutter_React Native Android_Flutter Dependencies - Fatal编程技术网

当我编写颤振插件时,如何获取android.app.Application对象

当我编写颤振插件时,如何获取android.app.Application对象,android,flutter,react-native-android,flutter-dependencies,Android,Flutter,React Native Android,Flutter Dependencies,当我使用flatter开发我的应用程序时,我需要使用第三方android SDK 这个SDK需要在我使用其他SDK函数之前很早初始化,这个初始化函数有参数,这些参数是来自android.app.Application的应用程序对象 但是,如何在plugin.java文件中获取这个应用程序对象,以便使用它定义一个可以使用的函数呢 有人告诉我有一个导入io.flatter.app.flatterApplication;类,但它是不可编辑的,即使我可以编辑它,我也没有地方使用它,所以我仍然无法初始化我

当我使用flatter开发我的应用程序时,我需要使用第三方android SDK

这个SDK需要在我使用其他SDK函数之前很早初始化,这个初始化函数有参数,这些参数是来自android.app.Application的应用程序对象

但是,如何在plugin.java文件中获取这个应用程序对象,以便使用它定义一个可以使用的函数呢

有人告诉我有一个导入io.flatter.app.flatterApplication;类,但它是不可编辑的,即使我可以编辑它,我也没有地方使用它,所以我仍然无法初始化我的SDK

以下是我的想法,但还不够好:

公共类应用程序扩展了应用程序{ .... @超级呼叫 创建时的公共无效{ super.onCreate; MySDK.initthis_应用程序_对象,param1,param2 flattermain.startinializationthis; } .... }
您可以像这样获得应用程序上下文

public class CloudSdkPlugin implements MethodCallHandler {

    private static Context context;

     public static void registerWith(Registrar registrar) {
        context=registrar.activity().getApplication();

      }
    }

您可以像这样获得应用程序上下文

public class CloudSdkPlugin implements MethodCallHandler {

    private static Context context;

     public static void registerWith(Registrar registrar) {
        context=registrar.activity().getApplication();

      }
    }

您通常必须为插件用户提供在其应用程序中调用此初始化的说明。请参见firebase_消息说明作为示例。在插件中,您可以在example/android应用程序中执行此操作。在onCreate中,只需使用getApplication。您通常必须为插件用户提供在其应用程序中调用此初始化的说明。请参见firebase_消息说明作为示例。在插件中,您可以在example/android应用程序中执行此操作。在onCreate中,只需使用getApplication。