无法共享文件(通过Gmail或Google云端硬盘)

时间:2013-12-11 14:57:47

标签: android

我有以下代码来共享文件。

这一切似乎都很好,

Gmail随附附件

打开

但是当我点击SEND时,Gmail会停止并发出错误Unfortunately Gmail has stopped

与Google云端硬盘相同,一切似乎都运行良好,但最终我得到: Google驱动器Upload failed

非常感谢任何帮助!!!

share.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            fileuri=Utility.downloadDb(MainActivity.this);
            if(fileuri!=null){
                Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(Intent.EXTRA_STREAM, fileuri);
                startActivity(sharingIntent);
            }
        }
    });

Utility.downloadDb(MainActivity.this); 是:

public static Uri downloadDb(Context context) {
    DatabaseHandler db= new DatabaseHandler(context);
    ArrayList<Word> list=new ArrayList<Word>();
    Uri fileuri=null;
    list.clear();
    list.addAll(db.getAllWords());
    File path = Environment
            .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    File file = new File(path, "db.csv");
    try {
        file.createNewFile();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    try {
        // Make sure the Pictures directory exists.
        path.mkdirs();

        FileWriter outFile = new FileWriter(file);
        PrintWriter out = new PrintWriter(outFile);
        out.print("PICTURE NAME");
        out.print(",");
        out.print("WORD NUMBER");
        out.print(",");
        out.print("LEFT");
        out.print(",");
        out.print("TOP");
        out.print(",");
        out.print("RIGHT");
        out.print(",");
        out.println("BOTTOM");

        for(int i=0;i<list.size();i++){
            out.print(list.get(i).pic);
            out.print(",");
            out.print(Integer.toString(list.get(i).wordno));
            out.print(",");
            out.print(Integer.toString(list.get(i).beginx));
            out.print(",");
            out.print(Integer.toString(list.get(i).beginy));
            out.print(",");
            out.print(Integer.toString(list.get(i).endx));
            out.print(",");
            out.println(Integer.toString(list.get(i).endy));


        }

        out.close();
        Toast.makeText(context, "SAVED TO: " +file.getAbsolutePath(), Toast.LENGTH_LONG).show();
        fileuri=Uri.parse(file.getAbsolutePath());
    } catch (IOException e) {
        // Unable to create file, likely because external storage is
        // not currently mounted.
        Log.e("ExternalStorage", "Error writing " + file, e);
    }
    return fileuri;
}

1 个答案:

答案 0 :(得分:1)

找到解决方案!!!!

我认为这对其他人也有用!!!

获取URI使用: fileuri=Uri.fromFile(file);

NOT 了fileURI = Uri.parse(file.getAbsolutePath());