//if send email button clicked
//check bytes and attach to mail
if (bytes.length > 0) {
try {
createCachedFile(this, attachmentFileName, bytes);
this.startActivity(getSendEmailIntent(this, "[email protected]", "Test", "See attached", attachmentFileName));
} catch (IOException e) {
e.printStackTrace();
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "Gmail is not available on this device.", Toast.LENGTH_SHORT).show();
}
}
public void createCachedFile(Context context, String fileName, byte[] content) throws IOException {
File cacheFile = new File(context.getCacheDir() + File.separator + fileName);
cacheFile.createNewFile();
BufferedOutputStream bostream = new BufferedOutputStream(new FileOutputStream(cacheFile));
bostream.write(content);
bostream.flush();
bostream.close();
}
public static Intent getSendEmailIntent(Context context, String email, String subject, String body, String fileName) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
//Explicitly only use Gmail to send
// emailIntent.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
//emailIntent.setType("message/rfc822");
emailIntent.setType("vnd.android.cursor.item/email");
//Add the recipients
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { email });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
//Add the attachment to custom ContentProvider
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + AttachFileProvider.AUTHORITY + "/" + fileName));
return emailIntent;
}
コンテンツがあなたのpdfファイルのバイト配列です:あなたはウル入力PDFファイルバイト配列を受け取るために、このような何かをしようとしたことがありますか? –
はい..入力ストリームで作成されたbytearray ..次のコードを使用して......... public byte [] returnPDFBytes(InputStream inStream) { byte [] tempbytes = null; try { BufferedInputStream bis =新しいBufferedInputStream(インストリーム); DataInputStream dis =新しいDataInputStream(bis); tempbytes =新しいバイト[dis.available()]; int i = 0; while(dis.available()> 0){ tempbytes [i] = dis.readByte(); i ++; } return tempbytes; } –