2013-04-03 10 views
6

ContentProviderを使用して添付ファイル付きのメールを送信しています。添付ファイル付きのメールを送信するAndroidが常に機能しない

  1. まず、ファイルをキャッシュディレクトリに書き込みます。
  2. 次に、コンテンツプロバイダが検索する各ファイルのURLを含む電子メールを作成します。
  3. 次に、ACTION_SEND_MULTIPLEインテントを使用して新しいアクティビティを開始します。
  4. 私はgmailを選択し、送信ボタンを押します。

これは時々動作しますが、しばらくの間は動作しているようですが、その後の試行後は動作していないようですが、必ずしもそうではありません。

メールが正しく送信されない場合は、Gmailでメールを送信できません。これは2.3.3と4.0.1で起こります.gmailクライアントでメールを開き、送信ボタンを押すとメッセージはほとんどの場合瞬時に配信されますが、毎回ではありません。

Googleドライブでインテントを開くと、gmailと同じ動作になります。

組み込みの交換メールクライアントを使用してインテントを開くと、これまでのところ動作します。ここで

は、電子メールを送信するためのコードです:ここで

  Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
      sendIntent.putExtra(Intent.EXTRA_EMAIL, exportParams.emailAddresses); 
      sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Leader Activity Report"); 
      sendIntent.putExtra(Intent.EXTRA_TEXT, "Leader Activity Report, see attached file."); 
      Uri fileUri = CachedFileProvider.createFileUri(result.fileName); 
      if (L.dbg()) 
       L.dbg("Using uri:" + fileUri.toString()); 
      ArrayList<Uri> uris = new ArrayList<Uri>(); 
      uris.add(fileUri); 
      Uri fileUri2 = CachedFileProvider.createFileUri(result.fileNameDayByDay); 
      uris.add(fileUri2); 
      if (L.dbg()) 
       L.dbg("Using uri2:" + fileUri2.toString()); 
      sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 
      sendIntent.setType("text/plain"); 
      parent.startActivity(sendIntent); 

は成功したと「停滞のメールの両方のコンテンツプロバイダ

public class CachedFileProvider extends ContentProvider { 

private static final String CLASS_NAME = "CachedFileProvider"; 
public static final String AUTHORITY = "com.josh.lll.file.provider"; 

private UriMatcher uriMatcher; 

@Override 
public boolean onCreate() { 
    uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); 
    uriMatcher.addURI(AUTHORITY, "*", 1); 
    return true; 
} 


@Override 
public ParcelFileDescriptor openFile(Uri uri, String mode) 
     throws FileNotFoundException { 
    try { 
     String LOG_TAG = CLASS_NAME + " - openFile"; 
     Log.v(LOG_TAG, 
       "Called with uri: '" + uri + "' - " + uri.getLastPathSegment()); 
     switch (uriMatcher.match(uri)) { 
     case 1: 
      String fileLocation = getContext().getCacheDir() + File.separator 
        + uri.getLastPathSegment(); 
      Log.i(CLASS_NAME,"Returning file :"+fileLocation); 
      ParcelFileDescriptor pfd = ParcelFileDescriptor.open(new File(
        fileLocation), ParcelFileDescriptor.MODE_READ_ONLY); 
      return pfd; 
     default: 
      Log.v(LOG_TAG, "Unsupported uri: '" + uri + "'."); 
      throw new FileNotFoundException("Unsupported uri: " 
        + uri.toString()); 
     } 
    } catch (FileNotFoundException t) { 
     Bug.major(this, t, "Could not return file descriptor"); 
     throw t; 
    } catch (RuntimeException t) { 
     Bug.major(this, t, "Could not return file descriptor"); 
     throw t; 
    } catch (Error t) { 
     Bug.major(this, t, "Could not return file descriptor"); 
     throw t; 
    } 
} 

public static String createFullyQualifiedFileName(Context c, String fileNamePart) { 
    File cacheDir = c.getCacheDir(); 
    Log.i(CLASS_NAME,"Using cache dir:"+cacheDir); 
    return cacheDir + File.separator + fileNamePart; 
} 

public static Uri createFileUri(String fileNamePart) { 
    return Uri.parse("content://" + AUTHORITY + "/"+ fileNamePart); 
} 

public int update(Uri uri, ContentValues contentvalues, String s, 
     String[] as) { 
    return 0; 
} 

@Override 
public int delete(Uri uri, String s, String[] as) { 
    return 0; 
} 

@Override 
public Uri insert(Uri uri, ContentValues contentvalues) { 
    return null; 
} 

@Override 
public String getType(Uri uri) { 
    return null; 
} 

@Override 
public Cursor query(Uri uri, String[] projection, String s, String[] as1, 
     String s1) { 
    return null; 
} 

}

は、次のログメッセージを送信していますGmailによって印刷されます:

04-03 22:17:35.027: I/Gmail(13206): >>>>> Attachment uri: content://com.josh.lll.file.provider/report_20100401_20130402_LeadetJosh_3_1364980653516.csv 
04-03 22:17:35.035: I/Gmail(13206): >>>>>   type: text/plain 
04-03 22:17:35.035: I/Gmail(13206): >>>>>   size: 0 
04-03 22:17:35.054: I/Gmail(13206): >>>>> Attachment uri: content://com.josh.lll.file.provider/backup_20100401_20130402_LeadetJosh_3_1364980653516_day_by_day.lll 
04-03 22:17:35.054: I/Gmail(13206): >>>>>   type: text/plain 
04-03 22:17:35.054: I/Gmail(13206): >>>>>   size: 0 
+0

すべてのファイル名に一意の文字列を追加すると、この問題は解決しません。それは私がしたいことではありません。 – placebojim

+0

うん。実際にはそれはかなり離れていません。 – placebojim

+2

ねえ、あなたはこの問題を解決できましたか?私は似たようなものに走っていますが、私の場合、電子メールは送信されますが、添付ファイルはありません。私は同じログメッセージを得るが、サイズは正しい。 – Pin

答えて

-3

治療法を見つける:

  • Gmailを無効にする。
  • 工場出荷時のデフォルトにリセットされます。
  • 電源を入れ直したときと同じように電話機を再起動します。
  • Gmailを有効にします。

は再び

1

それは/データ/アプリまたは/システムなどのシステムフォルダに保存されたファイルのために発生した添付ファイルのために働く必要があります。

これらのファイルは、sdcardの場所にコピーし、そこから添付して使用してください。

関連する問題