I'm trying to let my application send a binary file through mail, telegram or any other app which can manage general files.
The code:
@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;
}
When I chose the mail application,for example, to send it, it told me that "Can not add this attachment".Why is that?