我正在尝试将文件从我在 android 手机上的应用程序发送到其他设备(它们可能是也可能不是 android 手机)。
我发送文件的整个代码是:
try{
File dir = getCacheDir();
File f;
try {
f = File.createTempFile("card", ".Xcard", dir);
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.setType("*/*");
i.putExtra(i.EXTRA_STREAM, Uri.fromFile(f));
startActivity(i);
} catch (IOException e) {
// TODO Auto-generated catch block
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}catch(Exception e){
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
}
但是我的文件没有被发送到手机??代码有什么问题?是不是因为接收手机无法识别我的“.Xcard”文件?
但我认为这不是问题,因为我尝试将“apk”文件发送到另一台设备,即使它不理解 apk 文件,它也收到了。(我正在尝试使用非安卓手机)。
那为什么不发送我发送的文件?是因为它是在 Cache 目录中创建的吗?