Srihari
Srihari

Reputation: 2429

Attachment is not attaching with email

I developing small android application. In that user want to take backup of SQLite database so i try to attach the SQLite database to mail, when i run this app on android device, a dialog open n displaying Gmail & some other app. When I choose Gmail it automatically displaying send mail id, subject, email content and attachment also, now I click send mail was sent to corresponding email. When I check that Email attachment is not available their ?? Why SQLite Database didn't attached ? what is wrong with my code ?

File getdbdatapath= Environment.getDataDirectory();
String currentDBPath = "/data/com.example.appname/databases/dbname/"; 
File path=new File(getdbdatapath, currentDBPath);
Log.d("Path", path.toString());

//File extdb= Environment.getExternalStorageDirectory();
//String extpath=extdb+"/NewFolder/dbname";
//File pathp=new File(extdb, extpath);
//Log.d("New Path", pathp.toString());

Log.i(getClass().getSimpleName(), "send  task - start");

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

String address = "[email protected]";
String subject = "Application Database";
String emailtext = "Please check the database as attachement";

//emailIntent.setType("Application/database");
//emailIntent.setType("text/html");
//emailIntent.setType("message/rfc822");            
emailIntent.setType("vnd.android.cursor.dir/email");  

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { address });

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);

emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + path));

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext);

startActivity(Intent.createChooser(emailIntent, "Send Mail..."));

I referred this link1 link2 link3, changed mailIntent.setType("text/html"); to many setTypes. Get database from external also, but didn't work. Help me. Thanks in advance.


This code is working fine

String extpath=Environment.getExternalStorageDirectory() +"/NewFolder/dbname";
File pathp=new File(extpath);

in my above code it take mnt>sdcard>mnt>sdcard>NewFloder>dbname so unable to attach now this code is working fine.

Upvotes: 0

Views: 700

Answers (1)

ligi
ligi

Reputation: 39539

you need to copy your file to a place where the email activity can access it. E.g. to sdcard.

Upvotes: 1

Related Questions