【发布时间】:2017-03-12 11:09:10
【问题描述】:
我正在使用 android studio 开发一个 android 移动应用程序,用户可以在其中发送 .txt 作为附件 ........它正在发送邮件但没有附件
电子邮件代码 .... 如果需要更改,请告诉我............ 当我尝试发送时没有显示附件 toast ......我认为这意味着我提供了正确的路径
public void Send(View view){
Uri docUri=Uri.parse("android.resource://com.example.shaz.geotag/files/GeotagDatabase.txt");
intent =new Intent(Intent.ACTION_SEND);
if(docUri!=null){
intent.putExtra(Intent.EXTRA_STREAM,docUri);}
else {
Toast.makeText(this, "No attachment", Toast.LENGTH_LONG).show();
}
intent.setType("message/rfc822");
intent.setData(Uri.parse("mailto:"));
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT,"Attached GeotagDatabase.txt");
chooser=Intent.createChooser(intent,"Sending Email....");
startActivity(chooser);
}
生成 .txt 的代码
生成 .txt 时,它显示路径为 txt/data/user/0/com.example.shaz.geotag/files/GeotagDatabase.txt
public String Attach()
{
SQLiteDatabase db =this.getWritableDatabase();
String[] columns={CoL_1, CoL_2, CoL_3};
Cursor cursor;
cursor = db.query(TABLE_NAME,columns,null,null,null,null,null);
StringBuffer stringBuffer= new StringBuffer();
File file =null;
FileOutputStream fileOutputStream=null;
while (cursor.moveToNext()){
int index1= cursor.getColumnIndex(CoL_1);
int index2= cursor.getColumnIndex(CoL_2);
int index3= cursor.getColumnIndex(CoL_3);
int id =cursor.getInt(index1);
String latitude =cursor.getString(index2);
String longitude =cursor.getString(index3);
try{
file=c.getFilesDir();
fileOutputStream = c.openFileOutput("GeotagDatabase.txt", Context.MODE_PRIVATE);
String text1= Integer.toString(id)+" ";
String text2=latitude+" ";
String text3=longitude+"\n";
fileOutputStream.write(text1.getBytes());
fileOutputStream.write(text2.getBytes());
fileOutputStream.write(text3.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Toast.makeText(c, "ADDED to txt"+file+"/GeotagDatabase.txt", Toast.LENGTH_LONG).show();
stringBuffer.append(id+" "+latitude+" "+longitude+"\n");
}
return stringBuffer.toString();
}
【问题讨论】: