Android 将sqlite数据写入html文件,并将html文件作为附件发送电子邮件
在我的应用程序中,我必须将Html文件中的sqlite数据作为报告发送,这意味着我必须将sqlite数据写入Html文件,在此之后,此html文件应作为附件附加到电子邮件中。现在,我正在使用emailIntent.putExtra方法Htmlf格式发送sqlite数据。但这应作为邮件发送到mail。但我希望在我的设备上保存一些类似html的文件。或者创建新的html文件并将sqlite数据写入其中,并作为附件发送。使用代码:只需获取sql数据并存储为字符串,然后使用OutputStreamWriter将其写入,并将文件作为附件添加Android 将sqlite数据写入html文件,并将html文件作为附件发送电子邮件,android,html,sqlite,Android,Html,Sqlite,在我的应用程序中,我必须将Html文件中的sqlite数据作为报告发送,这意味着我必须将sqlite数据写入Html文件,在此之后,此html文件应作为附件附加到电子邮件中。现在,我正在使用emailIntent.putExtra方法Htmlf格式发送sqlite数据。但这应作为邮件发送到mail。但我希望在我的设备上保存一些类似html的文件。或者创建新的html文件并将sqlite数据写入其中,并作为附件发送。使用代码:只需获取sql数据并存储为字符串,然后使用OutputStreamWri
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String data = "<html><body> My name is John.</body></html>";
String uri = Environment.getExternalStorageDirectory()+"";
File f = new File(uri,"san.html");
if(!f.exists()){
try {
f.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
FileOutputStream fout;
try {
fout = openFileOutput(uri,MODE_WORLD_WRITEABLE);
OutputStreamWriter osw = new OutputStreamWriter(fout);
osw.write(data);
osw.flush();
osw.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent emailintent = new Intent(Intent.ACTION_SEND);
emailintent.setType("text/html");
emailintent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(f));
emailintent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailintent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(f));
emailintent.putExtra(Intent.EXTRA_TEXT, "Enjoy the Attachments");
startActivity(Intent.createChooser(emailintent, "Email:"));
}
}
您不能写入资产,但可以写入常规文件。请注意质量问题。例如,演示您的尝试和具体问题。@laalto…谢谢你。可以将html文件保存到其他位置或创建html文件并将一些数据写入itjadhav…非常感谢你…给出了很好的答案。但是这一行的give error fout=openFileOutputuri,MODE_WORLD_WRITEABLE;由于java.lang.IllegalArgumentException:File/mnt/sdcard/san.html包含路径分隔符,请更改此行字符串uri=Environment.getExternalStorageDirectory+;文件f=新文件URI,san.html;在代码中,将权限添加到您的AndroidManifestFileandSandIP…现在我更改代码,但不发送附件,这会导致问题EmailIntent.putExtraIntent.EXTRA\u流,Uri.fromFilef;emailintent.AddFlagsInt.FLAG\授予\读取\ URI\权限;只要添加此权限并将一行Uri.parse更改为Uri.fromFile,如果有任何困难,请告诉我