1

私は、ユーザーが Gmail 経由でコンテンツを共有できるようにする Android アプリケーションに取り組んでいます。Androidバージョン2.2(Froyo)を使用しています。問題は、これに対する有効な解決策が見つからないことです。ほとんどすべてを試しましたが、うまくいきませんでした。これは私が使用しているコードです:

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 タイプを置き換え、ファイルを text/html として表示し、これを処理できるアプリケーション リストに私のアプリケーションが表示されないことです。ファイルの種類。もう 1 つの制限は、インテント フィルターで text/html を使用したくないということです。これは、可能な限りフォーカスを当てたいためです。可能であれば、独自の MIME タイプを定義します...

私は少し調査を行い、この質問を見つけましたが、答えはありません...

私が試したその他の MIME タイプ:

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

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

ありがとう。

4

2 に答える 2

0

「圧縮」に関する部分の以前の回答を改善します。これで、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();  
                  }  
    }  
  }  
于 2013-10-12T07:32:21.147 に答える