2017-01-03 3 views
0

나는 android APK 확장 파일을 가지고 있으며 PDF 파일이 몇 장 있습니다. 공식 문서에서 그들은 Inputstream을 통해 .obb 내부의 파일에 액세스합니다. 입력 스트림을 통해 .obb 내부의 파일에 액세스 할 수 있습니다.이메일에 입력 스트림을 첨부하십시오.

이제 Intent가 포함 된 이메일에 파일 중 하나를 첨부하고 싶습니다. E-Mail 인 텐트는 애셋의 파일로 완벽하게 작동하므로 문제는 Inputstream을 첨부하는 것입니다.

PDF를 .obb에서 직접 메일에 첨부하려면 어떻게해야합니까?

+0

가능한 복제 [방법 안드로이드에서 파일이 첨부 된 이메일을 보내 (http://stackoverflow.com/questions/9974987/how-to-send-an-email-with-a-file - 안드로이드 어택) – StarWind0

답변

0

그것을 해결!

Inputstream을 임시 파일로 변환하고 해당 파일의 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...")); 
관련 문제