Esempio n. 1
0
 /**
  * Check the {@link PackageManager} if the phone has an application installed to view this type of
  * attachment. If not, {@link #viewButton} is disabled. This should be done in any place where
  * attachment.viewButton.setEnabled(enabled); is called. This method is safe to be called from the
  * UI-thread.
  */
 public void checkViewable() {
   if (viewButton.getVisibility() == View.GONE) {
     // nothing to do
     return;
   }
   if (!viewButton.isEnabled()) {
     // nothing to do
     return;
   }
   try {
     Uri uri = AttachmentProvider.getAttachmentUriForViewing(mAccount, part.getAttachmentId());
     Intent intent = new Intent(Intent.ACTION_VIEW);
     intent.setData(uri);
     intent.addFlags(
         Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
     if (intent.resolveActivity(mContext.getPackageManager()) == null) {
       viewButton.setEnabled(false);
     }
     // currently we do not cache re result.
   } catch (Exception e) {
     Log.e(
         K9.LOG_TAG,
         "Cannot resolve activity to determine if we shall show the 'view'-button for an attachment",
         e);
   }
 }
Esempio n. 2
0
  public void showFile() {
    Uri uri = AttachmentProvider.getAttachmentUriForViewing(mAccount, part.getAttachmentId());
    Intent intent = new Intent(Intent.ACTION_VIEW);
    // We explicitly set the ContentType in addition to the URI because some attachment viewers
    // (such as Polaris office 3.0.x) choke on documents without a mime type
    intent.setDataAndType(uri, contentType);
    intent.addFlags(
        Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    try {
      mContext.startActivity(intent);
    } catch (Exception e) {
      Log.e(K9.LOG_TAG, "Could not display attachment of type " + contentType, e);
      Toast toast =
          Toast.makeText(
              mContext,
              mContext.getString(R.string.message_view_no_viewer, contentType),
              Toast.LENGTH_LONG);
      toast.show();
    }
  }