从一个游戏应用程序(C++ 中)读取文件到我的 android 应用程序
To read a file from one gaming application(in C++) to my android app
我想从我的 android 应用中读取另一个目录中的文本文件,即游戏目录 (/sdcard/Android/data/game_package_name/files)。
请问有什么办法吗,有的话请指教
注意:这是针对生产级别的应用程序,因此请避免任何特定于 root 的功能。
基本上,你cannot access another application's sandbox。
但是,如果您可以修改其他应用程序,则可以使用 ContentProvider 或类似的共享解决方案来提供从其他应用程序访问此特定文件的权限。
将共享文件存储在共享文件夹中
由于您希望从不同的应用程序访问文件,而其中一个应用程序的沙箱将无法从另一个应用程序访问,因此您应该将文件写入两个都可以访问的目录中,例如:
String fileName = Environment.getExternalStorageDirectory().getPath() + "myFolderForBothApplications/myFileNameForBothApplications.txt";
使用内容提供商
如果您希望将文件保留为一个应用程序的一部分,您仍然可以通过 ContentProvider 公开信息。
在其中,覆盖 public ParcelFileDescriptor openFile(Uri uri, String mode)
method, and in the other application, just use the method getContentResolver().openInputStream(...)
.
这里有一些相关主题的链接,我无耻地 copied/pasted 代码来自:
How to access /data folder of another application through your application?
我想从我的 android 应用中读取另一个目录中的文本文件,即游戏目录 (/sdcard/Android/data/game_package_name/files)。
请问有什么办法吗,有的话请指教
注意:这是针对生产级别的应用程序,因此请避免任何特定于 root 的功能。
基本上,你cannot access another application's sandbox。 但是,如果您可以修改其他应用程序,则可以使用 ContentProvider 或类似的共享解决方案来提供从其他应用程序访问此特定文件的权限。
将共享文件存储在共享文件夹中
由于您希望从不同的应用程序访问文件,而其中一个应用程序的沙箱将无法从另一个应用程序访问,因此您应该将文件写入两个都可以访问的目录中,例如:
String fileName = Environment.getExternalStorageDirectory().getPath() + "myFolderForBothApplications/myFileNameForBothApplications.txt";
使用内容提供商
如果您希望将文件保留为一个应用程序的一部分,您仍然可以通过 ContentProvider 公开信息。
在其中,覆盖 public ParcelFileDescriptor openFile(Uri uri, String mode)
method, and in the other application, just use the method getContentResolver().openInputStream(...)
.
这里有一些相关主题的链接,我无耻地 copied/pasted 代码来自:
How to access /data folder of another application through your application?