io.realm.exceptions.RealmMigrationNeededException Java Examples
The following examples show how to use
io.realm.exceptions.RealmMigrationNeededException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpectreApplication.java From quill with MIT License | 7 votes |
private void setupMetadataRealm() { final int METADATA_DB_SCHEMA_VERSION = 4; Realm.init(this); RealmConfiguration config = new RealmConfiguration.Builder() .modules(new BlogMetadataModule()) .schemaVersion(METADATA_DB_SCHEMA_VERSION) .migration(new BlogMetadataDBMigration()) .build(); Realm.setDefaultConfiguration(config); // open the Realm to check if a migration is needed try { Realm realm = Realm.getDefaultInstance(); realm.close(); } catch (RealmMigrationNeededException e) { // delete existing Realm if we're below v4 if (mHACKOldSchemaVersion >= 0 && mHACKOldSchemaVersion < 4) { Realm.deleteRealm(config); mHACKOldSchemaVersion = -1; } } AnalyticsService.logMetadataDbSchemaVersion(String.valueOf(METADATA_DB_SCHEMA_VERSION)); }
Example #2
Source File: GreenHubDb.java From batteryhub with Apache License 2.0 | 5 votes |
public GreenHubDb() { try { mRealm = Realm.getDefaultInstance(); } catch (RealmMigrationNeededException e) { // handle migration exception io.realm.exceptions.RealmMigrationNeededException e.printStackTrace(); } }
Example #3
Source File: BaseApplication.java From JalanJalan with Do What The F*ck You Want To Public License | 5 votes |
@Override public void onCreate() { super.onCreate(); instance = this; try { Realm.getInstance(this); } catch (RealmMigrationNeededException expected) { Realm.deleteRealmFile(this); // Delete old realm } }
Example #4
Source File: MainApplication.java From StudentAttendanceCheck with MIT License | 4 votes |
@Override public void onCreate() { super.onCreate(); Fabric.with(this, new Crashlytics()); Contextor.getInstance().init(getApplicationContext()); // setup RealmConfiguration // RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this).build(); // Realm.setDefaultConfiguration(realmConfiguration); try { config = new RealmConfiguration.Builder() .deleteRealmIfMigrationNeeded() .schemaVersion(0) .rxFactory(new RealmObservableFactory()) .build(); Realm.setDefaultConfiguration(config); } catch (RealmMigrationNeededException rme) { config = new RealmConfiguration.Builder() .name(DATABASE_NAME) .deleteRealmIfMigrationNeeded() .build(); Realm.setDefaultConfiguration(config); } catch (Exception e) { Realm.init(this); config = new RealmConfiguration.Builder() .name(DATABASE_NAME) .deleteRealmIfMigrationNeeded() .build(); Realm.setDefaultConfiguration(config); Log.e("MainApplication initListener: " + e.getMessage(),e.toString()); } finally { Realm.init(this); Realm.getDefaultInstance().setAutoRefresh(true); Log.e("MainApplication TaninTest: ", Realm.getDefaultInstance().getPath() ); } }
Example #5
Source File: PowerConnectionReceiver.java From batteryhub with Apache License 2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) return; boolean isCharging = false; String batteryCharger = ""; if (intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) { isCharging = true; final Intent mIntent = context.getApplicationContext() .registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (mIntent == null) return; int chargePlug = mIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; boolean wirelessCharge = false; if (Build.VERSION.SDK_INT >= 21) { wirelessCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_WIRELESS; } if (acCharge) { batteryCharger = "ac"; EventBus.getDefault().post(new PowerSourceEvent("ac")); } else if (usbCharge) { batteryCharger = "usb"; EventBus.getDefault().post(new PowerSourceEvent("usb")); } else if (wirelessCharge) { batteryCharger = "wireless"; EventBus.getDefault().post(new PowerSourceEvent("wireless")); } } else if (intent.getAction().equals(Intent.ACTION_POWER_DISCONNECTED)) { isCharging = false; EventBus.getDefault().post(new PowerSourceEvent("unplugged")); } // Post to subscribers & update notification int batteryRemaining = (int) (Battery.getRemainingBatteryTime(context, isCharging, batteryCharger) / 60); int batteryRemainingHours = batteryRemaining / 60; int batteryRemainingMinutes = batteryRemaining % 60; EventBus.getDefault().post( new BatteryTimeEvent(batteryRemainingHours, batteryRemainingMinutes, isCharging) ); // Notifier.remainingBatteryTimeAlert( // context, // batteryRemainingHours + "h " + batteryRemainingMinutes + "m", isCharging // ); try { // Save a new Battery Session to the mDatabase GreenHubDb database = new GreenHubDb(); LogUtils.logI(TAG, "Getting new session"); database.saveSession(Inspector.getBatterySession(context, intent)); database.close(); } catch (IllegalStateException | RealmMigrationNeededException e) { LogUtils.logE(TAG, "No session was created"); e.printStackTrace(); } }