J. Staunstrup
J. Staunstrup

Reputation: 13

Realm SyncConfiguration

I am trying to synchronize a Realm database on my Android phone and a local Realm Objectserver similar to the RealmsTasks example in the documentation. I am using this code:

String authURL = "http://localhost:9080/auth";
SyncCredentials myCredentials = SyncCredentials.usernamePassword(
        "...", "...", false); //user is in Realm database

SyncUser.loginAsync(myCredentials, authURL, this);
Log.i("TINGLE","credentials checked");

SyncConfiguration defaultConfig = new SyncConfiguration.Builder(
      currentUser(), 
      "http://localhost:9080/~/realmtingle").build();
Realm.setDefaultConfiguration(defaultConfig);

However, the call to SyncConfiguration.Builder gives an exception. The error might be the path "http://localhost:9080/~/realmtingle", but has not been able to find guidelines on what the path should be in the Realm documentation.

The exception is: ....

 Caused by: java.lang.IllegalArgumentException: Invalid scheme: http
 at io.realm.SyncConfiguration$Builder.validateAndSet(SyncConfiguration.java:320)
 at io.realm.SyncConfiguration$Builder.<init>(SyncConfiguration.java:293)
 at io.realm.SyncConfiguration$Builder.<init>(SyncConfiguration.java:280)
 at dk.staunstrups.tingle.TingleActivity.setUpRealmSync(TingleActivity.java:74)
 at dk.staunstrups.tingle.TingleActivity.onCreate(TingleActivity.java:38)
...

Upvotes: 0

Views: 652

Answers (1)

Christian Melchior
Christian Melchior

Reputation: 20126

The Realm URL should use realm: or realms:. It is only authentication that uses http. Below should work:

String authURL = "http://localhost:9080/auth";
SyncCredentials myCredentials = SyncCredentials.usernamePassword(
        "...", "...", false); //user is in Realm database

SyncUser.loginAsync(myCredentials, authURL, this);
Log.i("TINGLE","credentials checked");

SyncConfiguration defaultConfig = new SyncConfiguration.Builder(
      currentUser(), 
      "realm://localhost:9080/~/realmtingle").build();
Realm.setDefaultConfiguration(defaultConfig);

Upvotes: 2

Related Questions