Android mobile usage history NetworkStatsManager
<p>I'm making an App for Android 6.0 and I want to use the new class NetworkStatsManager for getting mobile data usage.</p>

<p>I added all permission I need in manifest and require the permission runtime.</p>

<p>When I call the method:</p>

<pre><code>bucket = networkStatsManager.querySummaryForDevice(ConnectivityManager.TYPE_WIFI, "", fromDate.getTime(), toDate.getTime());
</code></pre>

<p>return the right value for WIFI usage.</p>

<p>But if i replace TYPE_WIFI with TYPE_MOBILE the result is always 0.</p>

<pre><code>    NetworkStats.Bucket bucket = null;
    try {
        bucket = networkStatsManager.querySummaryForDevice(ConnectivityManager.TYPE_MOBILE, "", fromDate.getTime(), toDate.getTime());

        if(bucket == null){
            Log.i("Info", "Error");
        }else{
            Log.i("Info", "Total: " + (bucket.getRxBytes() + bucket.getTxBytes()));
        }

    } catch (RemoteException e) {
        e.printStackTrace();
    }
</code></pre>