2017-01-03 6 views
0

私はアンドロイドAPK拡張ファイルを持っていますが、いくつかのPDFがあります。 公式の文書では、Inputstream経由で.obb内のファイルにアクセスします。私は、入力ストリーム経由で.obbの中のファイルにアクセスすることができます。メールに入力ストリームを添付する

ここで、ファイルの1つをインテントの電子メールに添付します。 Eメールインテントは、アセットからのファイルで完全に正常に動作するため、問題はInputstreamを取り付けることです。

PDFを.obbから直接メールに添付するにはどうすればよいですか?

+0

の可能性のある重複[アンドロイドで添付ファイルを電子メールで送信する方法](http://stackoverflow.com/questions/9974987/how-to-send-an-email-with-a-fileアタッチメント・イン・アンドロイド) – StarWind0

答えて

0

はそれを解決します!

入力ストリームをテモラリファイルに変換し、そのファイルのUriを取得して電子メールインテントに添付する必要があります。

Intent i = new Intent(Intent.ACTION_SEND); 
    i.setType("application/pdf"); 

    try { 
     ZipResourceFile expansionFile = new ZipResourceFile("Path to .obb file"); 
     InputStream fileStream = expansionFile.getInputStream("Path inside .obb"); 

     String downloadordner = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(); //used for temp storage 

     File tempFile = new File(downloadordner+"/"+"filename.pdf"); 
     tempFile.deleteOnExit(); 
     FileOutputStream out = new FileOutputStream(tempFile); 
     IOUtils.copy(fileStream, out); 

     Uri theUri = Uri.fromFile(tempFile); 

     i.putExtra(Intent.EXTRA_STREAM, theUri); 
     startActivity(Intent.createChooser(i, "PDF versenden...")); 
    } catch (android.content.ActivityNotFoundException ex) { 
     Toast.makeText(preisliste.this, "Es wurde kein E-Mail Client gefunden.", Toast.LENGTH_SHORT).show(); 
    } 
    catch (IOException e) 
    { 
     Log.v("Datei nicht gefunden","Main Expansion"); 
    } 
0

See this SO answer

String filename="yourfile"; 
File filelocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), filename); 
Uri path = Uri.fromFile(filelocation); 
Intent emailIntent = new Intent(Intent.ACTION_SEND); 
// set the type to 'email' 
emailIntent .setType("vnd.android.cursor.dir/email"); 
String to[] = {"[email protected]"}; 
emailIntent .putExtra(Intent.EXTRA_EMAIL, to); 
// the attachment 
emailIntent .putExtra(Intent.EXTRA_STREAM, path); 
// the mail subject 
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject"); 
startActivity(Intent.createChooser(emailIntent , "Send email...")); 
関連する問題