tray
tray copied to clipboard
Accessing Outside of Container App
there is documentation or functionallity about how to use TrayPreferences with an external App?
something like:
public class AppPreferencesManager extends TrayPreferencesConnector {
// setting up access:
// like uri of Tray ContentProvider
}
so we can use
AppPreferencesManager appPref;
appPref.put(key,value);
storedValue = appPref.get(key,value);
from any app outside of app/module container.
I tried it, but it's not possible with the current API. I also tried it with reflection but due to some final fields it is not possible. You aren't able to use the TrayPreferences
API. Sorry for that, but Tray wasn't designed as a high level ContentProvider API. Also the versioning could lead to big problems.
But at least you're able to access the ContentProvider of the other app (if the provider is set to exported="true"
).
// read from other app
String module = "thatmodule";
String key = "thatkey";
final Cursor query = getContentResolver().query(Uri
.parse("content://my.other.app.authority.preferences/" + module + "/" + key), null,
null, null, null);
final String value = query.getString(query.getColumnIndexOrThrow("VALUE"));
// write to other app
final ContentValues values = new ContentValues();
values.put("VALUE", "myValue");
getContentResolver().insert(Uri.parse("content://my.other.app.authority.preferences/" + module + "/" + key), values);
all information can be found in the provider
package.
Also, have a look at https://github.com/owlr-com/SharedContentProviders which is exactly what you need
I need this too :/
Hey, I'd like to access the provider from an other app just like your example in your last comment, however, the provider's "exported" param is set to false deep within the library. Am I missing something ? Can I override this setting?
Thanks