0

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 = "clientmailid@gmail.com";
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.

Community
  • 1
  • 1
Srihari
  • 2,387
  • 9
  • 51
  • 82
  • keep file inside data folder will never work as that folder path can never be accessed by other apps. You need to keep the files to be attached on sdcard by making one folder on sdcard and putting/copying/moving files to that folder. – Rajen Raiyarela Sep 16 '14 at 14:55
  • @RajenRaiyarela hi I tried that method also, check above my code i comment that lines. `File extdb= Environment.getExternalStorageDirectory();` – Srihari Sep 17 '14 at 05:25

1 Answers1

1

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

ligi
  • 39,001
  • 44
  • 144
  • 244
  • Yeah I tried that method also check my code above i comment it now. `File extdb= Environment.getExternalStorageDirectory();` – Srihari Sep 16 '14 at 13:29
  • when I choose Gmail from dialog it will show exact Database name in both cases, then i sent mail to abc@gamil.com. Now if I check mail in abc@gmail.com mail received with out attachment. – Srihari Sep 16 '14 at 14:06
  • Sad, Am running app on android device, I copyed APK file and installed in my android device. In emulator problem with creating gmail account so. What can i do now ? whats wrong here ? – Srihari Sep 16 '14 at 14:29
  • you can also have the log from the android device – ligi Sep 16 '14 at 16:06
  • Thanks a lot for your valuable answer and time. Now working fine with small change in the code. – Srihari Sep 22 '14 at 06:42