Monitor network activity in Android Phones
TCPDUMP is one of my favourite tools for analyzing network, but if you find difficult to cross-compile tcpdump for android, I'd recomend you to use some applications from the market.
These are the applications I was talking about:
- Shark: Is small version of wireshark for Android phones). This program will create a *.pcap and you can read the file on PC with wireshark.
- Shark Reader : This program allows you to read the *.pcap directly in your Android phone.
Shark app works with rooted devices, so if you want to install it, be sure that you have your device already rooted.
Good luck ;)
how to monitor the traffic of an android
There is no need for an external server. You need to route the traffic from your phone to the device where the intercepter is running. You could create a mitm setup with a tool like https://mitmproxy.org/. Btw you will need a routed phone, something like xposed-ProxyOn.. Then you can intercept app specific traffic. But if you try to intercept https traffic from apps they use certificate pinning you wont get a connection to the app server
How to monitor other apps network usage?
Since android 7, you can query only your own app traffic usage. From TraffixStats.getUidRxBytes
docs:
Starting in
N
this will only report traffic statistics for the calling UID. It will return UNSUPPORTED for all other UIDs for privacy reasons. To access historical network statistics belonging to other UIDs, useNetworkStatsManager
.
Going to NetworkStatsManager
, you could use queryDetailsForUid
, but as documentation (https://developer.android.com/reference/android/app/usage/NetworkStatsManager.html) says:
NOTE: Calling
querySummaryForDevice(int, String, long, long)
or accessing stats for apps other than the calling app requires the permissionPACKAGE_USAGE_STATS
, which is a system-level permission and will not be granted to third-party apps. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application.
So be warned that the user must give some special permission to your app.
Edit:
I used once UsageStatsManager
, I think it's what you are looking for: https://developer.android.com/reference/android/app/usage/UsageStatsManager.html#queryUsageStats(int,%20long,%20long)
How to monitor network status in android
Your question is not clear!
If checking the network connection is what you want, the following will do.
// Check network connection
private boolean isNetworkConnected(){
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
Capturing mobile phone traffic on Wireshark
Here are some suggestions:
For Android phones, any network: Root your phone, then install tcpdump on it. This app is a tcpdump wrapper that will install tcpdump and enable you to start captures using a GUI. Tip: You will need to make sure you supply the right interface name for the capture and this varies from one device to another, eg -i eth0 or -i tiwlan0 - or use -i any to log all interfaces
For Android 4.0+ phones: Android PCAP from Kismet uses the USB OTG interface to support packet capture without requiring root. I haven't tried this app, and there are some restrictions on the type of devices supported (see their page)
For Android phones: tPacketCapture uses the Android VPN service to intercept packets and capture them. I have used this app successfully, but it also seems to affect the performance with large traffic volumes (eg video streaming)
For IOS 5+ devices, any network: iOS 5 added a remote virtual interface (RVI) facility that lets you use Mac OS X packet trace programs to capture traces from an iOS device. See here for more details
For all phones, wi-fi only: Set up your Mac or PC as a wireless access point, then run wireshark on the computer.
For all phones, wi-fi only: Get a capture device that can sniff wi-fi. This has the advantage of giving you 802.11x headers as well, but you may miss some of the packets
Capture using a VPN server: Its fairly easy to set-up your own VPN server using OpenVPN. You can then route your traffic through your server by setting up the mobile device as a VPN client and capture the traffic on the server end.
Related Topics
How to to Check If a User Has Rated Your App on the Google Play
Android - Running a Method Periodically Using Postdelayed() Call
How to Change the Led Intensity of an Android Device
Open Specific Activity When Notification Clicked in Fcm
List View Items Changes Position When Scrolling Android
Image Size for All Screen Devices
Android Studio: Creating Landscape Layouts
Editing Functionality of Host Card Emulation in Android
Gradle Sync Failed Could Not Find Constraint-Layout:1.0.0-Alpha2
Firebase Ontokenrefresh() Is Not Called
Clear Recent Apps Wipe the Apps Memory and My Receiver Stopped Working
Android Manifest Restrict to Tablets
Extract Black and White Image from Android Camera's Nv21 Format