1

data/data/com.example.XXXX/files/THISFILE.txt にあるファイルを添付したい

しかし、最初にSDにエクスポートして添付する必要があります。以下のコードがありますが、「hello.txt」ファイルが作成されていないため、添付できません。

public class exportar extends Activity {


String from = "/data/data/com.example.XXXXXX/files/THISFILE.txt";
String to = "/sdcard/hello.txt";


public static boolean copyFile(String from, String to) {
    try {
        int bytesum = 0;
        int byteread = 0;
        File oldfile = new File(from);
        if (oldfile.exists()) {
            InputStream inStream = new FileInputStream(from);
            FileOutputStream fs = new FileOutputStream(to);
            byte[] buffer = new byte[1444];
            while ((byteread = inStream.read(buffer)) != -1) {
                bytesum += byteread;
                fs.write(buffer, 0, byteread);
            }
            inStream.close();
            fs.close();
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);




   Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_SUBJECT,"XXX");
    i.putExtra(Intent.EXTRA_TEXT   , ("XXX"));


     String file = "file://" + Environment.getExternalStorageDirectory()+"/hello.txt";


    Uri uri = Uri.parse(file);
    i.putExtra(Intent.EXTRA_STREAM, uri);



    finish();
    try {
        startActivity(Intent.createChooser(i, "xxxx."));



    } catch (android.content.ActivityNotFoundException ex) {


        finish();
    }
}
}

任意の提案をいただければ幸いです。

編集済み 1

私は変わりました

String from = "/data/data/com.example.XXXXXX/files/THISFILE.txt";
String to = "/sdcard/hello.txt";

File ruta_data = Environment.getDataDirectory();
File from = new File(ruta_data.getAbsolutePath(), "com.example.aa/files/THISFILE.txt");


File ruta_sd = Environment.getExternalStorageDirectory();
File to = new File(ruta_sd.getAbsolutePath(), "Hello.txt");

data/data/ にあるので入れ getDataDirectory()たのですが n data/data/com.example.aa/files/THISFILE.txt だとどうしたらいいのかわかりません

SD のルートにコピーする場合、ruta_sd は正しいですか?

4

0 に答える 0