android-networking

Network traffic monitoring per android application

家住魔仙堡 提交于 2019-12-04 09:53:56
I was wondering if I can do network traffic monitoring per android application? Basically see which app is receiving/sending how much data? I know there are many apps which already do that but I want to know how to do it. Well you surely can. A very simple way is to use the TrafficStats class. It can manage per app (more formally, per UID) But the problem is, it can return UNSUPPORTED . When this happens, I don't think you will have some easy (i.e. using the high level Java language) method to get the network traffic data you need. Not sure if it can be implemented in Java as I imagine you

Is it possible to separate WebView's UI and HTTP threads?

▼魔方 西西 提交于 2019-12-04 02:53:51
问题 For various reasons, I need to runOnUiThread() the actual instantiation & initialization of WebView. Which means that its underlying HTTP connections are also made on the UI thread? If this is true, is it possible to separate the WebView's UI thead from the HTTP connections thread? If it is possible, what is the proper way of accomplishing this? 回答1: I find it very hard to believe that Android would run remote HTTP requests on the UI thread, assuming you initiate the requests via WebView

Unit testing a network response. Works when debugging, not when actually running

喜你入骨 提交于 2019-12-03 17:50:39
问题 I am currently attempting to test that a network response is actually being received. While I understand that this isn't what I should be doing with regards to testing, its a curiosity of my own volition and I'd like to carry on if possible. As it stands, I have successfully created the test. A request is sent to a volley queue without issue. Now the odd part: That request is never executed. Here's an idea of how I'm testing it: @Test public void testSimpleGetResponseFromServerVolley() throws

Unable to access Internet via WiFi from a Background service

依然范特西╮ 提交于 2019-12-03 15:29:22
I'll get straight onto some facts/figures I discovered pls help me if you've faced/solved a similar problem. I send back data every 5 minutes to a server unless the user manually toggles it Off with the help of a wakeful broadcast receiver through a intent service . Plus I get wifi locks before doing (I've tried this already without locks; doesnt work either) Now on devices sending back data from regular data networks (2G/3G/4G) this works fine but on those connected to a wifi network somehow gets me a getActiveNetworkInfo() as null (Even directly hitting the web URL gives a hostname not found

Cannot make a static reference to the non-static method getSystemService(String) from the type

夙愿已清 提交于 2019-12-03 13:06:02
问题 I have this function which network connection public boolean isNetworkConnected() { ConnectivityManager conManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = conManager.getActiveNetworkInfo(); if (netInfo == null) { // There are no active networks. return false; } else { return true; } } But when i a trying to make it static so that i can use it in every activity it is throwing: Cannot make a static reference to the non-static method

Simulate Slow Internet Connection on a REAL device? [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-03 12:14:55
This question already has answers here : Simulate low bandwidth in android (11 answers) I need to test my application in conditions where even 2G Internet connectivity isn't at its full coverage (i.e. 2 bars instead of 4, 2G). I prefer conducting these tests over WiFi. Is there a way (programmatically or otherwise) to tell the Android OS on the real device to slow down or throttle Internet connection 56 Kbit/s? Note: I know how to do this on the emulator . I'm looking for a way to do this on a real device . Is this possible? In one of your comments you mentioned that you have a DD-WRT router,

Android API-23: InetAddressUtils replacement

夙愿已清 提交于 2019-12-03 11:13:10
问题 Switching to Android Marshmallow API, I was using org.apache.http.conn.util.InetAddressUtils for InetAddressUtils.isIPv4Address(ipAddress) in a code to list all IPs from a device. As part of the API-23 changes, the InetAddressUtils class is now gone. How can I replace the below code now? public static String ipAddress() { try { for (final Enumeration<NetworkInterface> enumerationNetworkInterface = NetworkInterface.getNetworkInterfaces(); enumerationNetworkInterface.hasMoreElements();) { final

Capture network traffic programmatically (no root)

余生长醉 提交于 2019-12-03 09:41:06
问题 I'm trying to find resources or library which could permit me to capture the traffic of all the network packets of a device programmatically either it be from wifi or mobile network. I believe there no need to be root to be in this promiscuous mode as shark for root would request because there is this app on the play store which can capture all network traffic (even decrypt SSL with MITM) without needing to be root. I simply cannot figure out how to do the same. My question is: How did this

How to change the network state of device from source code in Android?

独自空忆成欢 提交于 2019-12-03 09:14:33
I am trying to change the network state of the device from the source code. I observed that there is a permission to grant to the applications for changing the network state i.e., CHANGE_NETWORK_STATE. But I am not able to find any example or code that can change the network state of a device. Please let me know if anyone knows or have an example to change the network state of a device. Regards, SSuman185 Suman This code is working. I got it from here . private void setMobileDataEnabled(Context context, boolean enabled) { try { final ConnectivityManager conman = (ConnectivityManager) context

Unit testing a network response. Works when debugging, not when actually running

倖福魔咒の 提交于 2019-12-03 06:34:25
I am currently attempting to test that a network response is actually being received. While I understand that this isn't what I should be doing with regards to testing, its a curiosity of my own volition and I'd like to carry on if possible. As it stands, I have successfully created the test. A request is sent to a volley queue without issue. Now the odd part: That request is never executed. Here's an idea of how I'm testing it: @Test public void testSimpleGetResponseFromServerVolley() throws Exception { final CountDownLatch signal = new CountDownLatch(1); NetworkClass.NetworkListener listener