Android 通过其他应用发送序列化文件

Android 通过其他应用发送序列化文件,android,Android,你好,我做了序列化的对象文件,我想通过,messenger,gmail,sms等发送。我试着用这种方式发送,这是从保存到发送的代码。我知道没有一个应用程序与此连接 File file=new File(getFilesDir() + "ShoppingList.ur"); try{ FileOutputStream fileOutputStream =new FileOutputStream(file);

你好,我做了序列化的对象文件,我想通过,messenger,gmail,sms等发送。我试着用这种方式发送,这是从保存到发送的代码。我知道没有一个应用程序与此连接

File file=new File(getFilesDir() + "ShoppingList.ur");
                try{
                    FileOutputStream fileOutputStream =new FileOutputStream(file);
                    ObjectOutputStream data=new ObjectOutputStream(fileOutputStream);
                    data.writeObject(toShare);
                    data.close();
                    fileOutputStream.close();
                }catch(IOException e){
                    e.printStackTrace();
                }
                uriToSend=Uri.fromFile(file);
                Intent shareIntent=new Intent(Intent.ACTION_SENDTO);
                shareIntent.addCategory("*/*");
                shareIntent.putExtra(Intent.EXTRA_STREAM,uriToSend);
                startActivity(Intent.createChooser(shareIntent,getString(R.string.sendTo)));
                file.delete();
你好,我制作了序列化的对象文件,我想通过,messenger,gmail,sms等发送它

我知道没有一个应用程序与此连接

大约有零个应用程序具有
*/*

此外:

  • ACTION\u SENDTO
    需要一个
    Uri
    mailto:
    smsto:
    方案,通常)

  • 您尚未为此文件指定MIME类型(例如,
    应用程序/octet流
    ,因为它没有正式的MIME类型)

  • 不要使用字符串连接来组合文件路径-将
    新文件(getFilesDir()+“ShoppingList.ur”)
    替换为
    新文件(getFilesDir(),“ShoppingList.ur”)

  • 您正在尝试使用该文件,即使您有未创建该文件的异常

  • 在其他应用程序有机会对文件执行任何操作之前,您正在删除该文件

  • 其他应用程序无法访问您应用程序的
    getFilesDir()
    ,因此无法使用此文件

  • Android 7.0+上禁止将
    Uri
    file
    方案(
    Uri.fromFile()
    )结合使用,以用于
    targetSdkVersion
    为24或更高版本的应用程序