Android 通过其他应用发送序列化文件
你好,我做了序列化的对象文件,我想通过,messenger,gmail,sms等发送。我试着用这种方式发送,这是从保存到发送的代码。我知道没有一个应用程序与此连接Android 通过其他应用发送序列化文件,android,Android,你好,我做了序列化的对象文件,我想通过,messenger,gmail,sms等发送。我试着用这种方式发送,这是从保存到发送的代码。我知道没有一个应用程序与此连接 File file=new File(getFilesDir() + "ShoppingList.ur"); try{ FileOutputStream fileOutputStream =new FileOutputStream(file);
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类型(例如,
,因为它没有正式的MIME类型)应用程序/octet流
- 不要使用字符串连接来组合文件路径-将
替换为新文件(getFilesDir()+“ShoppingList.ur”)
新文件(getFilesDir(),“ShoppingList.ur”)
- 您正在尝试使用该文件,即使您有未创建该文件的异常
- 在其他应用程序有机会对文件执行任何操作之前,您正在删除该文件
- 其他应用程序无法访问您应用程序的
,因此无法使用此文件getFilesDir()
- Android 7.0+上禁止将
与Uri
方案(file
)结合使用,以用于Uri.fromFile()
为24或更高版本的应用程序targetSdkVersion