createPackageContext를 통해 다른 응용 프로그램의 자원에 접근할 수 없습니다 (Sharepreference)

2266 단어 android
자세히 보기
이전에 우리는createPackageContext를 통해 다른 응용 프로그램의 자원(Sharepreference)에 접근할 수 있었지만, 안드로이드 7.0 이후 안전성을 위해 이런 방식을 버렸다.
PS:
/**
     * File creation mode: allow all other applications to have read access to
     * the created file.
     *
     * As of {@link android.os.Build.VERSION_CODES#N} attempting to use this
     * mode will throw a {@link SecurityException}.
     *
     * @deprecated Creating world-readable files is very dangerous, and likely
     *             to cause security holes in applications. It is strongly
     *             discouraged; instead, applications should use more formal
     *             mechanism for interactions such as {@link ContentProvider},
     *             {@link BroadcastReceiver}, and {@link android.app.Service}.
     *             There are no guarantees that this access mode will remain on
     *             a file, such as when it goes through a backup and restore.
     * @see android.support.v4.content.FileProvider
     * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
     */
    @Deprecated
    public static final int MODE_WORLD_READABLE = 0x0001;
MODEWORLD_READABLE 같은 방식으로 SharePreference 회보 Security Exception을 만듭니다.
01-08 05:32:21.465 16339 16339 E AndroidRuntime: Caused by: java.lang.SecurityException: MODE_WORLD_READABLE no longer supported
01-08 05:32:21.465 16339 16339 E AndroidRuntime:        at android.app.ContextImpl.checkMode(ContextImpl.java:2134)
01-08 05:32:21.465 16339 16339 E AndroidRuntime:        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:354)
01-08 05:32:21.465 16339 16339 E AndroidRuntime:        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:349)
01-08 05:32:21.465 16339 16339 E AndroidRuntime:        at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:164)
01-08 05:32:21.465 16339 16339 E AndroidRuntime:        at com.android.deskclock.Utils.getCESharedPreferences(Utils.java:778)
01-08 05:32:21.465 16339 16339 E AndroidRuntime:        at com.android.deskclock.settings.DefaultAlarmToneDialog.(DefaultAlarmToneDialog.java:74)

좋은 웹페이지 즐겨찾기