Android sharing Files, by sending them via email or other apps Android sharing Files, by sending them via email or other apps java java

Android sharing Files, by sending them via email or other apps


this is the code for sharing file in android

Intent intentShareFile = new Intent(Intent.ACTION_SEND);File fileWithinMyDir = new File(myFilePath);if(fileWithinMyDir.exists()) {    intentShareFile.setType("application/pdf");    intentShareFile.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+myFilePath));    intentShareFile.putExtra(Intent.EXTRA_SUBJECT,                        "Sharing File...");    intentShareFile.putExtra(Intent.EXTRA_TEXT, "Sharing File...");    startActivity(Intent.createChooser(intentShareFile, "Share File"));}


sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(exportPath));

also you can make zip file of all file and attach zip file for send multiple file in android


This is work for every single file!

private void shareFile(File file) {    Intent intentShareFile = new Intent(Intent.ACTION_SEND);    intentShareFile.setType(URLConnection.guessContentTypeFromName(file.getName()));    intentShareFile.putExtra(Intent.EXTRA_STREAM,        Uri.parse("file://"+file.getAbsolutePath()));    //if you need    //intentShareFile.putExtra(Intent.EXTRA_SUBJECT,"Sharing File Subject);    //intentShareFile.putExtra(Intent.EXTRA_TEXT, "Sharing File Description");    startActivity(Intent.createChooser(intentShareFile, "Share File"));}

Thanks Tushar-Mate!