Exemple #1
0
  /**
   * This method create a intent for posting a tweet on twitter by using the twitter app.
   *
   * @param tweetMessage message which should be posted
   */
  public static void tweetWithApp(String tweetMessage) {
    if (tweetMessage != null) {
      Intent tweetIntent = new Intent(Intent.ACTION_SEND);
      tweetIntent.putExtra(Intent.EXTRA_TEXT, tweetMessage);
      tweetIntent.setType("text/plain");
      tweetIntent.setFlags(
          Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

      PackageManager packManager = CreateContextForResource.getContext().getPackageManager();
      List<ResolveInfo> resolvedInfoList =
          packManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY);

      boolean resolved = false;
      for (ResolveInfo resolveInfo : resolvedInfoList) {
        if (resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) {
          tweetIntent.setClassName(
              resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
          resolved = true;
          break;
        }
      }
      if (resolved) {
        CreateContextForResource.getContext().startActivity(tweetIntent);
      } else {
        Toast.makeText(
                CreateContextForResource.getContext(),
                CreateContextForResource.getStringFromID(R.string.twitter_not_found),
                Toast.LENGTH_LONG)
            .show();
      }
    }
  }
  private void getDepartmentSettingsForGUI() {
    try {
      departmentSettings = DepartmentObserver.readSettings();
    } catch (SettingsNotFoundException e) {
      Log.e(this.getClass().getSimpleName(), "Department Settings not found.");
      departmentSettings = new DepartmentSettingsModel();

      AlertDialog dialog;

      AlertDialog.Builder builder = new AlertDialog.Builder(this);

      builder
          .setTitle(
              CreateContextForResource.getStringFromID(
                  R.string.activity_department_settings_alert_dialog_title))
          .setMessage(
              CreateContextForResource.getStringFromID(
                  R.string.activity_department_settings_alert_dialog_text))
          .setCancelable(false)
          .setIcon(android.R.drawable.ic_dialog_info)
          .setPositiveButton(
              CreateContextForResource.getStringFromID(
                  R.string.activity_department_settings_alert_dialog_button),
              null);

      dialog = builder.create();

      dialog.show();
    }

    if (departmentSettings != null) {
      autoCompView.setText(departmentSettings.getAddress());
    }
  }