我需要在android上的两个独立应用之间共享一些特定数据,
最好制作某种共享文件夹,只能由两个应用程序访问。
为什么?我需要两个单独的应用程序之间的单一登录功能。
到目前为止,我一直在通过使用JWT token 对用户进行身份验证,方法是将它们存储在sharedpreferences中(存储它们以维护登录),并在用户注销时清除共享首选项(以及点击更改 token 的api)。
现在,我有另一个使用相同 token 的应用程序。
要求:您登录一个,然后另一个人自动登录。因此,我的计划是将 token 存储在设备上,然后两个应用程序都可以访问该 token 。
我知道我需要一个 Activity 目录来获得安全的SSO,但我现在还没有100%的安全性,这仍然是个问题,仍然是如何在应用程序之间共享数据。
最佳答案
我只是给你一个想法,更不用说这个了,仅在Android中有效。
Future<void> _createAndWrite() async {
// Get external directory
final directory = (await Directory('storage/emulated/0/Sharing Folder').create()).path;
// Create your file
final file = File('$directory/any_file.txt');
await file.create();
// Write to the file
await file.writeAsString('Content to write');
}
Future<void> _readFile() async {
// Get external directory
final directory = (await Directory('storage/emulated/0/Sharing Folder').create()).path;
// Get the file
final file = File('$directory/any_file.txt');
// Read it
final content = await file.readAsString();
}
确保在两个应用程序中都声明了以下权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
关于android - Flutter:如何在两个单独的android应用之间安全地共享数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62016073/