我试图让我的应用程序通过邮件,电报或任何其他可以管理一般文件的应用程序发送二进制文件。在Android中共享二进制文件
代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.circuit_menu, menu);
MenuItem item = menu.findItem(R.id.menu_item_share);
// Fetch and store ShareActionProvider
ShareActionProvider mShareActionProvider = (ShareActionProvider) item.getActionProvider();
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
File f = new File(getFilesDir(),circuit.getName() + ".obj");
if(f.exists()){
Log.d("FILE",f.getAbsolutePath());//Checking
}
Uri uri = Uri.parse(f.getAbsolutePath());
Log.d("URI",uri.toString());//Checking
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
Intent.createChooser(shareIntent, "Share via");
mShareActionProvider.setShareIntent(shareIntent);
return true;
}
当我选择的邮件应用程序,例如,送它,它告诉我,“不能添加此附件”。为什么会这样?
http://stackoverflow.com/questions/4646913/android-how-use-use-mediascannerconnection-scanfile – samosaris