How to attach database file to an Email in android?

前端 未结 2 757
不思量自难忘°
不思量自难忘° 2021-01-17 01:00

HI I am trying to send an email by attaching a database fie, i am getting mail without attaching the fallowing is my code. can any one help me..? try{

             


        
相关标签:
2条回答
  • 2021-01-17 01:41

    You can copy the file to the SDCard using the following code:

    File sd = Environment.getExternalStorageDirectory();
    File data = Environment.getDataDirectory();
    if (sd.canWrite()) {
        String currentDBPath = "\\data\\application.package\\databases\\name";
        String backupDBPath = "name";
        File currentDB = new File(data, currentDBPath);
        File backupDB = new File(sd, backupDBPath);
        if (currentDB.exists()) {
            FileChannel src;
        try {
        src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            try {
            dst.transferFrom(src, 0, src.size());
        src.close();
                dst.close();
            } catch (IOException e) {                                                    
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
        e.printStackTrace();
        }
    

    Remember to add the following permission: android:name="android.permission.WRITE_EXTERNAL_STORAGE"

    0 讨论(0)
  • 2021-01-17 01:48

    The email program can't access your application's private files, in this case, the database you are trying to send. Copy the database to a folder in the SD card and attach it from there.

    0 讨论(0)
提交回复
热议问题