Android Question NetworkPolicyManager - limitBytes, warningBytes

viljemto

Member
Licensed User
Longtime User
Hi

i am trying to get up and running NetworkPolicyManager (limitBytes, warningBytes).
https://stackoverflow.com/questions...by-user-on-android-os-confi/24445424#24445424

But I am getting error on inport libraries android.net.

Maybe somebody have any suggestion what would be wrong? Or even maybe other solution?
I am trying to get information, if data limit is enabled and what warning and limit is set.

Thank you!



B4X:
src\b4a\example\main.java:8: error: cannot find symbol
import android.net.NetworkPolicy;
                  ^
  symbol:   class NetworkPolicy
  location: package android.net


Java:
#If JAVA
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.net.Uri;

import android.net.Network;
import android.net.NetworkPolicy;
import android.net.NetworkPolicyManager;
   
import anywheresoftware.b4a.BA;



public void getBytes(){
    Intent intent = new Intent();
    Context context=this;

    NetworkPolicyManager manager = (NetworkPolicyManager) context.getSystemService(Context.NETWORK_POLICY_SERVICE);
    NetworkPolicy[] networkPolicies = manager.getNetworkPolicies();
   
    Log.d("NetworkPolicy", "limitBytes is " + networkPolicies[0].limitBytes);
    Log.d("NetworkPolicy", "warningBytes is " + networkPolicies[0].warningBytes);
   
    context.startActivity(intent);
}

#End If

2021-01-26_19-53-33.png
 

drgottjr

Expert
Licensed User
Longtime User
i can only respond to your first question:
Maybe somebody have any suggestion what would be wrong?
what would be wrong is you can't access these classes (NetworkPolicy, NetworkPolicyManager). tons of relative information if you spend some time googling those terms.
 
Upvote 0
Top