Search in sources :

Example 1 with NetworkStateReceiver

use of io.realm.internal.network.NetworkStateReceiver in project realm-java by realm.

the class SyncObjectServerFacade method init.

@Override
public void init(Context context) {
    //noinspection TryWithIdenticalCatches
    try {
        // FIXME: Reflection can be avoided by moving some functions of SyncManager and ObjectServer out of public
        Class<?> syncManager = Class.forName("io.realm.ObjectServer");
        Method method = syncManager.getDeclaredMethod("init", Context.class);
        method.setAccessible(true);
        method.invoke(null, context);
    } catch (NoSuchMethodException e) {
        throw new RealmException("Could not initialize the Realm Object Server", e);
    } catch (InvocationTargetException e) {
        throw new RealmException("Could not initialize the Realm Object Server", e);
    } catch (IllegalAccessException e) {
        throw new RealmException("Could not initialize the Realm Object Server", e);
    } catch (ClassNotFoundException e) {
        throw new RealmException("Could not initialize the Realm Object Server", e);
    }
    if (applicationContext == null) {
        applicationContext = context;
        applicationContext.registerReceiver(new NetworkStateReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    }
}
Also used : IntentFilter(android.content.IntentFilter) Method(java.lang.reflect.Method) NetworkStateReceiver(io.realm.internal.network.NetworkStateReceiver) RealmException(io.realm.exceptions.RealmException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

IntentFilter (android.content.IntentFilter)1 RealmException (io.realm.exceptions.RealmException)1 NetworkStateReceiver (io.realm.internal.network.NetworkStateReceiver)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1