Java – the world readable preference in honeycomb cannot be accessed

I have a free game and I'm making a paid version Free game in my mode_ WORLD_ Integer values are stored in the shared preferences file created in readable mode If the free version is installed, the paid version needs to copy this score

The code I'm using is as follows:

Context c = paidContext.createPackageContext("my.app.packagename",Context.CONTEXT_IGNORE_Security);
SharedPreferences prefs = c.getSharedPreferences(SHARED_PREF_FILENAME,Context.MODE_WORLD_READABLE);

The first line creates the context of the free application if it exists (otherwise an exception will occur) The second line gets the shared preferences file Then I can use prefs GetInt to get high scores

Problem: this works well in Android 1.5, 2.1, 2.3, etc., but it doesn't work for me in Android 3.0 or 3.1 emulators The above code runs, but getInt always returns the default value

Is this a mistake? A feature of honeycomb? Are there any application permissions I don't know? How can I make further diagnosis?

Solution

Although helpful, Rome's comments on the question did not provide an answer To extend it, Android does not guarantee cross process access to preferences; In fact, the document (at the top of shared preferences) clearly states that inter process access is not supported (even if it is valid) By signing the application with different certificates, you can ensure that the application cannot run in the same process. This is the sandbox method of Android

For its value, I initially tried to combine SharedPreferences with mode_ WORLD_ Readable is used together as a method of accessing data between two applications with different signatures I finally ran into a problem because in some cases interprocess reading didn't work (it seems to be a matter of operation order) Instead, I first implemented what I should do, that is, interprocess communication (IPC) using service Aidl

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>