示例#1
0
  /** On application creation. */
  @Override
  public void onCreate() {
    super.onCreate();
    sInstance = this;

    Connection.setContext(getApplicationContext());

    // Error Reporter
    CustomExceptionHandler customExceptionHandler = CustomExceptionHandler.getInstance();
    customExceptionHandler.Init(sInstance.getApplicationContext());
    Thread.setDefaultUncaughtExceptionHandler(customExceptionHandler);

    SharedPreferences preferences = PrefSettings.getSharedPrefs(this);
    // Assign some default settings if necessary
    if (preferences.getString(PrefSettings.KEY_CHECK_URI, null) == null) {
      Editor editor = preferences.edit();
      // Test Update Notifications
      // Some ridiculously fast polling, just to demonstrate it working...
      /*
       * editor.putBoolean(PrefSettings.KEY_ENABLED, true); editor.putLong(PrefSettings.KEY_PERIOD, 30 * 1000L);
       * editor.putLong(PrefSettings.KEY_CHECK_INTERVAL, 60 * 1000L); editor.putString(PrefSettings.KEY_CHECK_URI,
       * "http://ankidroid.googlecode.com/files/test_notifications.xml");
       */
      editor.putString(
          PrefSettings.KEY_CHECK_URI, "http://ankidroid.googlecode.com/files/last_release.xml");

      // Create the folder "AnkiDroid", if not exists, where the decks
      // will be stored by default
      new File(getStorageDirectory() + "/AnkiDroid").mkdir();

      // Put the base path in preferences pointing to the default
      // "AnkiDroid" folder
      editor.putString("deckPath", getStorageDirectory() + "/AnkiDroid");

      // Using commit instead of apply even though we don't need a return value.
      // Reason: apply() not available on Android 1.5
      editor.commit();
    }

    // Reschedule the checks - we need to do this if the settings have
    // changed (as above)
    // It may also necessary in the case where an application has been
    // updated
    // Here for simplicity, we do it every time the application is launched
    Intent intent = new Intent(Veecheck.getRescheduleAction(this));
    sendBroadcast(intent);
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    Log.d(LOG_TAG, "Receiver called");
    String action = intent.getAction();
    if (action == null) {
      return;
    }

    Log.v(LOG_TAG, "Receiver called with action: " + action);
    if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
      syncChecking(context);
    } else if (action.equals(Veecheck.getRescheduleAction(context))) {
      syncChecking(context);
    } else if (action.equals(Veecheck.getConsiderAction(context))) {
      considerChecking(context);
    }
  }