Android:检索其他应用程序的共享首选项
我有一个设置应用程序,我必须从中检索其他应用程序首选项,但我没有其中的键的详细信息,如何检索该首选项中的所有可用键和值?
谢谢, 斯瓦蒂
I have a settings application from which i have to retrieve other applications preferences, but i don't have the details of keys in them, how can i retrieve all the available keys and values in that preference?
Thanks,
Swathi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
好的!在应用程序 1(包名称为“com.sharedpref1”)中使用此代码来存储具有共享首选项的数据。
在应用程序2中使用此代码从应用程序1中的共享首选项中获取数据。我们可以获取它,因为我们在应用程序1中使用了MODE_WORLD_READABLE:
更多信息请访问此URL:
http://androiddhamu.blogspot.in/2012/03 /share-data-across-application-in.html
Okay! using this code in Application 1 ( with package name is "com.sharedpref1" ) to store data with Shared Preferences.
And using this code in Application 2 to get data from Shared Preferences in Application 1. We can get it because we use MODE_WORLD_READABLE in application 1:
More information please visit this URL:
http://androiddhamu.blogspot.in/2012/03/share-data-across-application-in.html
假设首选项是 WORLD_READABLE,这可能有效:
Assuming the preference are WORLD_READABLE, this might work:
此外,您必须在两个应用程序的清单文件中添加相同的 android:sharedUserId 。
Additionally you have to add same android:sharedUserId in the both app's manifest file.
不幸的是,现在的文档甚至没有解释 MODE_WORLD_READABLE 和 MODE_WORLD_WRITEABLE,而是说:
这个常量在 API 级别 17 中已被贬值。
创建世界可读的文件是非常危险的,并且可能会导致应用程序中的安全漏洞。强烈劝阻;相反,....etc
由于折旧,在具有共享首选项的应用程序之间实现文件共享可能风险太大,尽管它很简单。我不太关心游戏应用程序中 MODE_WORLD_READABLE 模式的安全漏洞,我只想能够将角色从一个应用程序传输到另一个应用程序。可惜他们贬低了这两种共享模式。
Unfortunately the docs now don't even explain MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE, instead saying:
This constant was depreciated in API level 17.
Creating world-readable files is very dangerous, and likely to cause security holes in applications. It is strongly discouraged; instead, ....etc
Since the depreciation, implementing file sharing between apps with sharedpreferences may be too risky, although it was simple. I'm not too concerned with security holes from the MODE_WORLD_READABLE mode in game apps where I just want to be able to transfer characters from one app to another. It's too bad they depreciated both sharing modes.
如果我们想从其他应用程序/pkg/Process读取peacorpely值,它可以工作。
但是Jkhouw1的答案中有问题:
不过:
但是,Context_ignore_security和mode_world_writ_writships具有相同的“ int 2”的值
完全感谢这个问题和答案。
It can work if we want read perference value from other app/pkg/process.
but there is something wrong in jkhouw1's answer:
It should be :
though , CONTEXT_IGNORE_SECURITY and MODE_WORLD_WRITEABLE with the same value of "int 2"
At all ,thanks for this question and answers.
continue
It's simple to retrieve store shared preferences data of one application to another application.
Step 1: add the same
android:sharedUserId="android.uid.shared"
in both app's manifest files.Step 2: Store Value application1
Step 3: Get Value From application2