Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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
如何从flatter代码读取或访问android代码中创建的共享首选项?_Android_Flutter_Sharedpreferences - Fatal编程技术网

如何从flatter代码读取或访问android代码中创建的共享首选项?

如何从flatter代码读取或访问android代码中创建的共享首选项?,android,flutter,sharedpreferences,Android,Flutter,Sharedpreferences,我以前在Play store中有一个完整的Android代码,没有flutter 现在我有一半的安卓代码和一半的颤振代码。我的希望是,当我从Flatter安装新应用程序时,当使用Android完整代码的旧应用程序登录时,当安装新应用程序时,它也会直接进入主页,因为它已登录 我如何阅读或访问?我保存在使用完整android代码的旧应用程序中的共享首选项登录数据 我尝试了invoke方法, 因此,从调用invoke method函数的flatter代码,该函数将android代码输入到flatter

我以前在Play store中有一个完整的Android代码,没有flutter 现在我有一半的安卓代码和一半的颤振代码。我的希望是,当我从Flatter安装新应用程序时,当使用Android完整代码的旧应用程序登录时,当安装新应用程序时,它也会直接进入主页,因为它已登录

我如何阅读或访问?我保存在使用完整android代码的旧应用程序中的共享首选项登录数据

我尝试了invoke方法, 因此,从调用invoke method函数的flatter代码,该函数将android代码输入到flatter应用程序本身,然后从android应用程序读取保存的共享首选项, 然后我返回到flatter代码发送共享的首选项,但我得到的只是空数据,即使我已经登录了

这是我的密码

颤振代码调用调用方法

const platform = const MethodChannel('com.startActivity/test');
final String result = await platform.invokeMethod('migrationAndroidToFlutter');
const platform = const MethodChannel('com.startActivity/test');
  platform.setMethodCallHandler((methodCall) async {
if(methodCall.method == "MigrationAndroidToFlutter"){
      var data = methodCall.arguments;
    var username = data[0];
    print(username);
}
}
Android代码

if (call.method.equals("migrationAndroidToFlutter"))
            {
val mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
val username = mSharedPreferences.getString(MessageKey.USERNAME, "")

val user = ArrayList<String>()
user.add(username)

sharedChannel.invokeMethod("SharedPreferenceAndroid", user)
}