Internet usage(Data usage) by WebView

1.3k views Asked by At

I have used WebView for browsing in my application, now i want to get internet usage by my WebView. Is it possible in android?

I have searched a lot but not getting even a single hint. Can anyone help me?

I know you will ask me what have you tried so far, but i didn't get anything from research. If anyone can give me hint, i am not asking for full code or example.

I have created simple webview and its working fine

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/webView1"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
/>
2

There are 2 answers

0
CommonsWare On

There is no means for you to determine the bandwidth consumed just by your WebView.

Depending on how your app is written, if you can determine how much bandwidth you are using outside of WebView, you can use TrafficStats to determine your whole app's bandwidth uses, and then subtract the two values to determine what is inside the WebView.

0
user1649464 On

Webview essentially is a DOM Tree which renders objects. It parses your HTML tags , creates elements and helps draw objects on a webpage. All the request for download goes as an http/https etc. request to android framework services. The webview does not know how much of data has been downloaded. It only requests for data and receives the contents/response back.

You should look into the code of Data usage activity/fragment in Settings applications. This will tell you how it monitors and tracks data of various applications but there is no suupport present in the framework(yet) to know which webview has downloaded how much content.