now_world
now_world

Reputation: 1096

phonegap android plugin for user preferences

I have two android apps, one written in Java and the other written in javascript wrapped in a phonegap application. I need my java app to set a user preference (string) and the js app to get this string.

After setting the user preference in my java app, I now need to know how to retrieve it in my js app. How? I have tried two phonegap plugins, (https://github.com/macdonst/AppPreferences and https://github.com/apla/me.apla.cordova.app-preferences)

However they don't seem to be built to get user preferences from other apps.

What else should I try? Should I stick with user preferences?

Thanks,

Upvotes: 0

Views: 306

Answers (2)

gokhanakkurt
gokhanakkurt

Reputation: 4953

Preferences are used and organised within the application context. This means that preferences of one application don't belong to other applications. There are some options that I suggest.

First Option

If one application defines a preference with MODE_WORLD_WRITEABLE mode, other application will be able to reach that preference if and only if package name is known. if preference is not defined with MODE_WORLD_WRITEABLE mode, preference will not be read by other application. MODE_WORLD_WRITEABLE is one the of modes in Preferences while defining new preference in Android. There is a previous thread that answers how to read other application's preferences. However, MODE_WORLD_WRITEABLE mode is deprecated in API level 17. If the target of your application is API Level 17 and over, you should not insist on Preferences.

Second Option

On the other hand, two applications can share the same Database on mobile device. You can simply create a table containing preferences that is shared and read by both two applications. Here is another link for this option that describes how to handle such operation.

Third Option

Other way, you can take the advantage of object Serialization in Java. I mean that, you can write a class that made up of configurations or preferences defined by your application. That class should implement Serializable interface. When it's required, that class can be written on a file or on a certain location that can be reachable by other applications. However, this option will not be secure because of consistency. File can be corrupted, removed and etc.

Fourth Option

As @BenSmith mentioned, you can store the preferences on a remote location that can be accessible by both two applications.

Upvotes: 6

tl8
tl8

Reputation: 537

One possible option is to write out a file with the settings and use the other app to read in the settings. I am not 100% sure an app can create files but it might be worth looking into.

Of course this may require user intervention (EG select the location of the saved file) so this might not work for you.

Failing that, the apps are mostly sandboxed so (As suggested by @BenSmith) a remote location is going to be your best bet.

Upvotes: 1

Related Questions