简体   繁体   English

如何保护我的应用程序文件在非根设备中被其他应用程序读/写?

[英]How to protect my app files being read/ write by other apps, in non-root device?

I was wondering, what is a good way, to prevent my app files from being read/ write to other apps, in non-root devices我想知道,什么是防止我的应用程序文件在非根设备中被读/写到其他应用程序的好方法

Currently, I'm storing my data (images, audio, ...) in getExternalFilesDir目前,我将数据(图像、音频等)存储在getExternalFilesDir

But, some of my users complain that, they are still able to see images in 3rd party gallery app.但是,我的一些用户抱怨说,他们仍然能够在 3rd 方图库应用中看到图像。

I am not sure whether they are using root phone.我不确定他们是否使用root电话。 So far, I cannot access my app getExternalFilesDir from Google Photo app.到目前为止,我无法从 Google Photo 应用程序访问我的应用程序getExternalFilesDir

Based on https://developer.android.com/training/data-storage , it seems that only getFilesDir will prevent other apps from accessing the files.基于https://developer.android.com/training/data-storage ,似乎只有getFilesDir会阻止其他应用程序访问文件。

But, is it appropriate for an app to store user data file in getFilesDir ?但是,应用程序将用户数据文件存储在getFilesDir中是否合适? (My app is a note taking app which needs to store user attachment images, audio, ...) (我的应用程序是一个笔记应用程序,它需要存储用户附件图像、音频……)

From discussion of Android getExternalFilesDir vs getFilesDir() for big files , it seems like getFilesDir is not designed to store user data files?Android getExternalFilesDir vs getFilesDir() for big files的讨论中,似乎getFilesDir不是为存储用户数据文件而设计的?

I was wondering, what is a good way, to prevent my app files from being read/ write to other apps, in non-root devices我想知道,什么是防止我的应用程序文件在非根设备中被读/写到其他应用程序的好方法

Store your data in internal storage (mostly getFilesDir() and getCacheDir() ).将数据存储在内部存储中(主要是getFilesDir()getCacheDir() )。

Currently, I'm storing my data (images, audio, ...) in getExternalFilesDir目前,我将数据(图像、音频等)存储在 getExternalFilesDir

The only reason to use that location is if you want the user to be able to use your content from outside of your app, whether via other apps or via an attached desktop computer.使用该位置的唯一原因是,如果您希望用户能够从您的应用程序外部使用您的内容,无论是通过其他应用程序还是通过连接的台式计算机。

In the long term, getExternalFilesDir() and getExternalCacheDir() will be off-limits to other apps — you will start seeing this on Android 11 in particular.从长远来看, getExternalFilesDir()getExternalCacheDir()将禁止使用其他应用程序——您将开始在 Android 11 上看到这一点。 However, it will take years for Android 11+ to dominate the Android device ecosystem.然而,Android 11+ 需要数年时间才能主导 Android 设备生态系统。

But, some of my users complain that, they are still able to see images in 3rd party gallery app.但是,我的一些用户抱怨说,他们仍然能够在 3rd 方图库应用中看到图像。

Such apps might be augmenting the MediaStore by scanning external storage for images.此类应用程序可能会通过扫描外部存储中的图像来扩充MediaStore

But, is it appropriate for an app to store user data file in getFilesDir?但是,应用程序将用户数据文件存储在 getFilesDir 中是否合适?

Yes.是的。 Everything should be in internal storage, unless there is a specific need for the user to be able to use the content outside of your app.一切都应该在内部存储中,除非用户特别需要能够在您的应用程序之外使用内容。 Internal storage should be your default choice, with external storage or the Storage Access Framework being explicit choices made to go against that default.内部存储应该是您的默认选择, 外部存储或存储访问框架是针对该默认值对 go 做出的明确选择。

From discussion of Android getExternalFilesDir vs getFilesDir() for big files, it seems like getFilesDir is not designed to store user data files?从 Android getExternalFilesDir vs getFilesDir() 的讨论来看,似乎 getFilesDir 不是为了存储用户数据文件而设计的?

Um, no.不。

A decade ago, internal storage and external storage were separate partitions, in part because external storage typically was implemented as removable storage (micro SD card).十年前,内部存储和外部存储是独立的分区,部分原因是外部存储通常被实现为可移动存储(微型 SD 卡)。 Since Android 3.0 in 2011, though, internal storage and external storage are almost always separate directories on the same partition.不过,自 2011 年 Android 3.0 以来,内部存储和外部存储几乎总是在同一分区上的不同目录。 The primary distinction between the two is what processes could access the files, with your portion of internal storage being locked down to just your app, and external storage being accessible by anything.两者之间的主要区别在于哪些进程可以访问文件,您的内部存储部分被锁定到您的应用程序,而外部存储可以被任何东西访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从“清洁工”和“优化工具”应用程序中保护我的Android应用程序文件? - Protect my Android app's files from “cleaners” and “optimizer” apps? 如何通过按后退按钮关闭非root活动的Android应用程序 - How to close an Android app from non-root activity by pressing the backbutton 存储,以便其他应用程序可以访问我的媒体/非媒体文件 - Storage so my media/non media files are accessible by other apps 如何读/写非root用户可以访问的文件? - How to read/write to a file that can be accessed by a user not being root? 如何在我的应用程序中隐藏其他应用程序? - How to Hide other apps from my app? 如何编写提供root设备功能的android应用程序? - How to write android app that provides the functionality to root the device? 当我的应用程序在前台时,如何防止其他应用程序读取 NFC 标签? - How to prevent other apps to read NFC tags when my app is in foreground? 在Android中从我的应用程序访问其他应用程序的GPX文件 - Access GPX files of other apps from my app, in android Android:如何检查我的其他应用程序是否已安装在设备上 - Android: How to check if my other apps are installed on a device 如何保护App中的Xml文件? - How to protect Xml files in App?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM