tray icon indicating copy to clipboard operation
tray copied to clipboard

Accessing Outside of Container App

Open ningacoding opened this issue 8 years ago • 3 comments

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.

ningacoding avatar Feb 19 '16 18:02 ningacoding

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

passsy avatar Feb 20 '16 10:02 passsy

I need this too :/

simc avatar Jun 02 '16 13:06 simc

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

dpattou avatar Feb 13 '17 11:02 dpattou