Any way to get what port is my app using? - android

I've search a lot and I can't get which port is my app using.
I tried using adb shell netstat -n but I'm not sure if this command is showing me anything related to my app.

Related

How to use ACTION_APP_NOTIFICATION_SETTINGS using adb shell command?

I need to open Notifications Setting for a specific app using adb shell command.
I found below post, which opens the Notification using code.
Any way to link to the Android notification settings for my app?
How can I implement this using adb shell?
I tried using below command:
"adb shell am start -a android.settings.ACTION_APP_NOTIFICATION_SETTINGS"
But according to documentation, we need to provide Package name of the app as an input. I am not sure how to provide the input using adb shell.
I am working on Android OS >= 9.
Thanks in advance.

ADB (android debug bridge) is unresponsive on Linux (Pop!_OS) with newest kernel

Any command I try to execute just results in the shell hanging and not doing anything until I interrupt it with CTRL + C. The below picture which illustrates the problem:
I've tried pretty much any solution I could find. This problem is NOT related to the android device.sudo adb kill-server has the same result as adb devices and I don't know how or where to start looking for Problems as anything like "debugging adb" or "troubleshooting adb" just pulls up tons of results of troubleshooting and debugging with adb.
I've already tried to reinstall adb, anything related to adb, and openjdk.
THE ANSWER:
some Java process was running and blocking ipv6 localhost, this caused ADB to basically just freeze because apparently it doesn't know what to do when the port it wants to use is blocked.
STEPS TO RESOLVE:
run with sudo (install net-tools via yum, apt etc. if not already installed):
netstat -ltnp | grep -w '5037'
this will show you the process ID of the process on port 5037 eg. 12345/foobar
then kill the process. Ideally only if you know it isn't a critical Process! run with sudo if necessary
kill 12345

Getting cpu and memory usage for a period of time

I have some old shell scripts that needs to be executed on an android device but the command to fetch the total cpu, memory and swap usage is top. More specific it is:
top -m 1 -d 1.0 -n $duration
Now I have been looking to find a replacement for this and I found out that I can use dumpsys. The problem what I have is that I want to give a timeout like this:
dumpsys -t 20 cpuinfo
I checked this site: https://developer.android.com/studio/command-line/dumpsys.html but didn't find out why this doesn't work. Even when I try the help I get the same error
dumpsys --help
Can't find the service: --help
Does someone know what is going on? My current android version is 6.0.1 if this is important.
Thanks in advance!
It is true that dumpsys --help does not work. I think there is a mistake in their document. However, below works:
# adb shell dumpsys input
# adb shell dumpsys -l
Add permission on your manifest "android.permission.DUMP".or
There's another (hacky) way to access dumpsys without rooting your device - through adb shell.
This will require allowing USB debugging, and finding the port of the adb service.
Enable USB debugging on your device. This option is found under Settings -> Developer Options.
Connect your device to a PC, and run the following command from the PC's shell/command line: adb tcpip 12345. Then, from your devices shell, issue the command adb connect localhost:12345 from your application. You can now disconnect the device from USB. Alternatively, you can scan the ports on your device one by one without USB connection, using adb connect localhost: and find the port adb service is listening to.
Authorize USB debugging from the pop up confirmation dialog, if prompted. Check the "always" checkbox to do not require this step again.
Now, when you have access to the adb service, use adb shell dumpsys ... from your application code to get whatever service dump you need.

android open homepage over the network

I know it is easy ,if I can use adb .
$ export ADBHOST=192.168.11.14(device's IP)
$ adb kill-server
$ adb start-server
in this status.I can use adb with wireless.so next,
$ adb shell am start -a android.intent.action.VIEW http://www.google.com
in this status. I can see google page in my android device .
I want to do it without adb. I want to develop a app which send a intent to one device via tcp without install any app. How can I do it?
You can't. Android doesn't wirelessly accept Intents from other devices, except via adb. It would be 100% insecure to do so- anyone could send any intent to anyone. It would be spam central. You need an app on both devices.

Sending AT commands from Powershell script to Android phone via adb

I have a little script that I run in adb shell of Android phone (/system/etc directory), which enables to communicate with the modem by sending/receiving a single AT command.
The script itself, if run in adb shell, works OK. That's what it looks like:
cat /dev/pts/7 &
echo -e $1\\r > /dev/pts/7
Here's the output in adb shell:
# ./sendATCommand "at+cops?"
./sendATCommand "at+cops?"
#
+COPS: 0,0,"AT&T",6
OK
/dev/pts/7: invalid length
(need to press ENTER to return control to adb shell)
#
Now I want to invoke this script from a powershell script running on my PC, thus eventually controlling modem via AT commands, but nothing happens.
For example, the below powershell script will send the command at+cops? to check the operator to which mobile is registered to:
$adb = [IO.Path]::Combine([IO.Path]::Combine($Env:ANDROID, "platform-tools"), "adb.exe")
& $adb remount
$atCommand = "at+cops?"
& $adb shell /system/etc/sendATCommand $atCommand
The output may looks sometimes like +ATCMD (any residual [proprietary]AT command sitting in device buffer after bootup), or at+cops?(echo), or nothing at all, but
never +COPS: 0,0,"AT&T",6 which I expect. Could you help me figure out what's going on and how to possibly fix it? Ideally
I want to be able to execute at command, return control to powershell, and have output available for further processing.
I am also open to other solutions to implement same thing.
Would greatly appreciate your help. Thanks!
Not sure to answer your question, my phone is not an Android, but when I connect it via buetooth or USB to my computer a COM port is created. So I build an assembly tool on the top of .NET SerialPort class that allow, for example, to send SMS using the phone Modem.
I think it's usable in your case.

Categories

Resources