Exemplo n.º 1
0
  private void submitReport(Report report, File logs) {
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    String densityBucket = getDensityString(dm);

    ShareCompat.IntentBuilder intent =
        ShareCompat.IntentBuilder.from(context)
            .setType("message/rfc822")
            // TODO: .addEmailTo("*****@*****.**")
            .setSubject(report.title);

    StringBuilder body = new StringBuilder();
    if (!Strings.isBlank(report.description)) {
      body.append("{panel:title=Description}\n").append(report.description).append("\n{panel}\n\n");
    }

    body.append("{panel:title=App}\n");
    body.append("Version: ").append(BuildConfig.VERSION_NAME).append('\n');
    body.append("Version code: ").append(BuildConfig.VERSION_CODE).append('\n');
    body.append("{panel}\n\n");

    body.append("{panel:title=Device}\n");
    body.append("Make: ").append(Build.MANUFACTURER).append('\n');
    body.append("Model: ").append(Build.MODEL).append('\n');
    body.append("Resolution: ")
        .append(dm.heightPixels)
        .append("x")
        .append(dm.widthPixels)
        .append('\n');
    body.append("Density: ")
        .append(dm.densityDpi)
        .append("dpi (")
        .append(densityBucket)
        .append(")\n");
    body.append("Release: ").append(Build.VERSION.RELEASE).append('\n');
    body.append("API: ").append(Build.VERSION.SDK_INT).append('\n');
    body.append("{panel}");

    intent.setText(body.toString());

    if (screenshot != null && report.includeScreenshot) {
      intent.addStream(Uri.fromFile(screenshot));
    }
    if (logs != null) {
      intent.addStream(Uri.fromFile(logs));
    }

    Intents.maybeStartActivity(context, intent.getIntent());
  }
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    String[] toList = new String[] {mAddress.getText().toString()};

    // IntentBuilder をインスタンス化
    ShareCompat.IntentBuilder builder = ShareCompat.IntentBuilder.from(CustomSendActivity.this);
    // データをセットする
    builder.setChooserTitle("Choose Send App");
    builder.setEmailTo(toList);
    builder.setSubject(mSubject.getText().toString());
    builder.setText(mMessage.getText().toString());
    builder.setType("text/plain");

    ShareCompat.configureMenuItem(menu, R.id.menu_share, builder);

    return true;
  }