File sharing fails for non-Google applications
<p>I use <a href="http://developer.android.com/reference/android/support/v4/content/FileProvider.html" rel="nofollow">FileProvider</a> to share my app's images. While it works perfectly for file sharing via gmail, hangouts, drive etc, I can not share file via non-Google apps ie WhatsApp, Viber. </p>

<p><a href="http://developer.android.com/reference/android/support/v4/content/FileProvider.html" rel="nofollow">FileProvider</a> in Androidmanifest</p>

<pre><code> &lt;provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="&lt;package.name&gt;.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true"&gt;
        &lt;meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filepaths" /&gt;
    &lt;/provider&gt;
</code></pre>

<p>filepath.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;paths&gt;
    &lt;files-path path="" name="export" /&gt;
&lt;/paths&gt;
</code></pre>

<p>Method for sharing file</p>

<pre><code>/**
 * Static method to export charts data
 *
 * @param mContext object context
 * @param view     chart to be converted into image
 * @throws IOException
 **/
public static void exportChartAsPng(Context mContext, View view) throws IOException {
    File baseDir = mContext.getFilesDir();
    Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");

    String fileName = "chart-" + df.format(calendar.getTimeInMillis()) + ".png";
    String filePath = baseDir.toString() + File.separator + fileName;
    File chartFile = new File(filePath);

    OutputStream outStream = new FileOutputStream(chartFile);
    getBitmapFromView(view).compress(Bitmap.CompressFormat.PNG, 100, outStream);
    outStream.flush();
    outStream.close();

    try {
        Uri fileUri = FileProvider.getUriForFile(
                mContext,
                "&lt;package.name&gt;.fileprovider",
                chartFile);


        Intent sendIntent = new Intent("&lt;package.name&gt;.ACTION_RETURN_FILE");
        if (fileUri != null) {
            // Grant temporary read permission to the content URI
            sendIntent.addFlags(
                    Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
        sendIntent.setType("image/png");
        mContext.startActivity(Intent.createChooser(sendIntent, mContext.getString(R.string.share)));

    } catch (IllegalArgumentException e) {
        Log.e("File Selector",
                "The selected file can't be shared: " +
                        chartFile.getName());
        e.printStackTrace();
    }

}
</code></pre>