2012-04-29 16 views
1

私はユーザーがGmail経由でコンテンツを共有できるようにするAndroidアプリケーションを開発中です。私はアンドロイド2.2(Froyo)を使っています。 問題は、私はこれのための実用的な解決策を見つけることができない、私はほとんどすべてを試みたが、運がないということです。 これは私が使用しているコードです:Android:GmailでZIPファイルを共有する

Intent sharingIntent = new Intent(Intent.ACTION_SEND);; 
sharingIntent.setType("application/zip"); 

sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
getString(R.string.share_subject)); 
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, getString(R.string.share_body)); 

String zipFile = FileProvider.URI_AUTHORITY + File.separator + mItemSelected.getLibraryName() + File.separator + mItemSelected.getZipFileName(); 

sharingIntent.putExtra(Intent.EXTRA_STREAM, android.net.Uri.parse(zipFile)); 
startActivity(Intent.createChooser(sharingIntent, (getString(R.string.share_chooser)))); 
} 

この場合の問題点は、Gmailアプリは、明白な理由のために、ファイルのMIMEタイプを交換され、およびテキスト/ HTMLなどのファイルを示すことがありますこの種類のファイルを扱うことができるアプリケーションリストに私のアプリケーションは表示されません。もう1つの制限は、私ができるだけ集中したいので、私のインテントフィルターでtext/htmlを使いたくないということです。もし可能であれば私自身のMIMEタイプを定義します。

私は少し研究を行なったし、このquestionを見つけましたが、ノーの答え...私が試した

以上のMIMEタイプで:

application/x-compressed, application/x-zip-compressed 
multipart/x-zip and application/octet-stream 

この問題のいずれかの解決策はあります?

ありがとうございました。

答えて

3

多くの問題の後、私はIntent経由で起動したGmailが接頭辞が.zipの添付ファイルが気に入らないことを発見しました。 添付ファイルを ".vip"という名前に変更して送信しました。ここ は、コードの一部(てoutFileは「.vip」と改名zipファイルである)である:

enter 
    private void sendMail(File outFile) { 
     Uri uriToZip = Uri.fromFile(outFile); 
     String sendText = "Dear friend,\n\n..."; 

     Intent sendIntent = new Intent(Intent.ACTION_SEND); 
     sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
      new String[] { "[email protected]" }); 
     sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, sendText); 
     sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Log of the test " + expFilename); 

    // sendIntent.setType("image/jpeg"); 
    // sendIntent.setType("message/rfc822"); 
     sendIntent.setType("*/*"); 
     sendIntent.putExtra(android.content.Intent.EXTRA_STREAM, uriToZip); 
     startActivity(Intent.createChooser(sendIntent, "Send Attachment !:")); 
    } 

それが助け場合は私に知らせてください。 よろしくお願いいたします。 FD

+1

これはKMZファイルの送信に使用します。素晴らしいです...(残念ながら)それは、Gmailのアプリの横に本当に関係のない余分なアプリをたくさん提供しています。 – nyaray

+0

Woop woop、私は[EXTRA_STREAM]を追加するだけで、[この他の回答](http://stackoverflow.com/questions/2197741/how-to-send-email-from-my-android-application) GMail、Googleドライブ、Skypeを候補アプリにする – nyaray

0

"zipping"に関する以前の回答を改善しました。今はGMailなどで送信された.zip添付ファイルに問題はありません。これを試してください:

{ 
       int lung; 
       FileInputStream in; 
       FileOutputStream out; 
       byte[] buffer = new byte[DIM_BUFFER]; 
    // compress the file to send 
       String inPath = ctx.getApplicationContext().getFilesDir().getAbsolutePath(); 
       outFile = new File(outPath,TestEdit.ZIPNAME); 
       // outFile = new File(outPath,filename + ".vip"); 
       in = new FileInputStream(inFile); 
       ZipEntry entry = new ZipEntry(filename + ".csv"); 
       try{ 
        out = new FileOutputStream(outFile); 
       // GZIPOutputStream zos; 
        ZipOutputStream zos; 
        zos = new ZipOutputStream(new BufferedOutputStream(out)); 
        zos.putNextEntry(entry); 
        try { 
         while ((lung=in.read(buffer)) > 0) { 
          Log.v(TAG, "Lunghezza di in=" + lung + ". Lungh di buffer=" + buffer.length); 
          if (buffer.length == lung) { 
           zos.write(buffer); 
          } else { 
           // Gestione del caso in cui il buffer non sia pieno 
           for (int b = 0; b < lung; b++) { 
            zos.write(buffer[b]); 
           } 
          } 
         } 
        } finally { 
         zos.closeEntry(); 
         zos.close(); 
         in.close(); 
         out.close(); 
        } 
    } 
    } 
関連する問題