示例#1
0
  /**
   * Get package name as defined in the manifest.
   *
   * @return the package name.
   */
  public static String getPkgName() {
    String pkgName = TAG;
    Context context = sInstance.getApplicationContext();

    try {
      PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
      pkgName = context.getString(pInfo.applicationInfo.labelRes);
    } catch (PackageManager.NameNotFoundException e) {
      Log.e(TAG, "Couldn't find package named " + context.getPackageName(), e);
    }

    return pkgName;
  }
示例#2
0
  /**
   * Get the package version as defined in the manifest.
   *
   * @return the package version.
   */
  public static String getPkgVersion() {
    String pkgVersion = "?";
    Context context = sInstance.getApplicationContext();

    try {
      PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
      pkgVersion = pInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
      Log.e(TAG, "Couldn't find package named " + context.getPackageName(), e);
    }

    return pkgVersion;
  }
示例#3
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);
  }
示例#4
0
 public static int getDisplayWidth() {
   Display display =
       ((WindowManager) sInstance.getApplicationContext().getSystemService(Context.WINDOW_SERVICE))
           .getDefaultDisplay();
   return display.getWidth();
 }