Android PreferenceActivity to create a MODE_WORLD_WRITEABLE preference across applications

独自空忆成欢 提交于 2019-12-05 21:29:25

To access preferences from another app in a secure way set the same android:sharedUserId in the Manifest. This will allow you to access preferences & files in MODE_PRIVATE (or secure) manner.

After much time spent, we realized this alone will not work and one needs to create a package context of the first app to access files in the second app:

try {
            Context c = createPackageContext(com.app.first, MODE_PRIVATE);
            SharedPreferences prefs = c.getSharedPreferences(
                    "com.app.first_preferences", MODE_PRIVATE);

        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }

A big thank you to @CommonsWare and Karthik Shanmugam for their help!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!