Can I mute a foreground app using ADB commands? - android

I have this adb shell command to mute an app with known package name
cmd appops set com.app.name PLAY_AUDIO deny
Rather than this, I want to send an adb command to mute the app which is currently in the foreground. What should be the adb command modification that will be required?
Thank you in advance

I found out the answer myself. The Tasker (android app) has the Appinfo function, whereby we can store the name of the foreground app in a local variable, and then we can run the ADB command using that local variable.

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.

How to close android application completely using adb or appium or any command line+python

I have tried to close android application using adb command and appium server but it is minimizing the app, not closing. I used below command for closing.
adb shell am force-stop com.package.name
AND if i try this command to kill process then it says,
adb shell kill 21860
Error:Operation omitted
Please let me know any way or command line to close android app completely, not run in background.
Thanks in advance!
I don't want to see in the background application list like below image.
adb shell am force-stop <PACKAGE-NAME>
Force stopS everything associated with <PACKAGE-NAME>
should work since honeycomb
Why not just:
un-installing app (it will stop any service or running process of it):
adb -s <udid> uninstall <appPackage>
and then installing it again:
adb -s <udid> install <apkPath>
Note:
In my case it is not working, because my app need to be registered each time re-installed, and working around it with 3rd app (e.g. Appium) is taking too long.

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.

How can I crash/kill a running app

I would like to crash my Android app by using command-line ADB tool during my app is running, is it possible to do? and how ?
(Basically, I want to test if my app persist the necessary informations when it is crashed. So, I would like to demo this by crash my app by some command-line tool, like ADB.)
***** Update ********
In other words, how to kill my app process by using ADB tool?
kill probably won't work.
adb shell am force-stop <your.app.package>
adb shell kill <PID>
Try the below command in abd shell.
You can kill your app from the shell:
adb -s YOURDEVICEID shell
top // find your app pid
kill -p YOUR_APP_PID
I can easily kill my app from Eclipse DDMS. Just stop the process , e.g. stop "com.my.app"
You can actually trigger a crash via the "crash" param to adb shell am
adb shell am crash <package name>
This is an obscure option but can be confirmed when emulator is running via: adb shell am help
Details: reference
crash [--user <USER_ID>] <PACKAGE|PID>
Induce a VM crash in the specified package or process
Wish this was easier to find I cannot find the original source where I found it but should be more obviously listed on docs page vs only shown when connected am help menu...
https://developer.android.com/studio/command-line/adb#am
App crashing at runtime is nothing but an Occurance of Exception, The place after which you want to crash your app, write a logic which causes for an Exception.
The best way to crash your app is to add an Exception to your package.
Like division by 0 - add it to your app code.
I don't know if you've got the answer yet. The answer is pretty much the same as #bas but instead of using , you need to you the package name
adb shell am force-stop <package name>
you can get the package name by using this command
adb shell pm list package -3
-3 means all 3rd party apps that are installed in device.

Stopping an Android app from console

Is it possible to stop an Android app from the console? Something like:
adb stop com.my.app.package
It would speed up our testing process so much. Right now we uninstall/install the app each time to make sure the manual test cases start with a clean state.
The clean way of stopping the app is:
adb shell am force-stop com.my.app.id
This way you don't have to figure out the process ID.
Edit: Long after I wrote this post and it was accepted as the answer, the am force-stop command was implemented by the Android team, as mentioned in this answer.
Alternatively: Rather than just stopping the app, since you mention wanting a "clean slate" for each test run, you can use adb shell pm clear com.my.app.package, which will stop the app process and clear out all the stored data for that app.
If you're on Linux:
adb shell ps | grep com.myapp | awk '{print $2}' | xargs adb shell kill
That will only work for devices/emulators where you have root immediately upon running a shell. That can probably be refined slightly to call su beforehand.
Otherwise, you can do (manually, or I suppose scripted):
pc $ adb -d shell
android $ su
android # ps
android # kill <process id from ps output>
First, put the app into the background (press the device's home button)
Then....in a terminal....
adb shell am kill com.your.package
you can use the following from the device console: pm disable com.my.app.package which will kill it. Then use pm enable com.my.app.package so that you can launch it again.
If you have access to the application package, then you can install with the -r option and it will kill the process if it is currently running as a side effect. Like this:
adb -d install -r MyApp.apk ; adb -d shell am start -a android.intent.action.MAIN -n com.MyCompany.MyApp/.MyActivity
The -r option preserves the data currently associated with the app. However, if you want a clean slate like you mention you might not want to use that option.
If you target a non-rooted device and/or have services in you APK that you don't want to stop as well, the other solutions won't work.
To solve this problem, I've resorted to a broadcast message receiver I've added to my activity in order to stop it.
public class TestActivity extends Activity {
private static final String STOP_COMMAND = "com.example.TestActivity.STOP";
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
TestActivity.this.finish();
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//other stuff...
registerReceiver(broadcastReceiver, new IntentFilter(STOP_COMMAND));
}
}
That way, you can issue this adb command to stop your activity:
adb shell am broadcast -a com.example.TestActivity.STOP
The "stop" command is implemented as force-stop; stops background app from running. If it's in foreground, it'll stop also: eg.
adb shell am force-stop com.android.providers.telephony
Clearing of packages also deletes their data eg.
adb shell pm clear com.android.providers.telephony
will delete all your sms
Be careful which one you choose.
adb shell killall -9 com.your.package.name
according to MAC "mandatory access control"
you probably have the permission to kill process
which is not started by root
have fun!
If all you are looking for is killing a package
pkill package_name
should work
I tried all answers here on Linux nothing worked for debugging on unrooted device API Level 23,
so i found an Alternative for debugging
From Developer Options -> Apps section -> check Do Not keep activities
that way when ever you put the app in background it gets killed
P.S remember to uncheck it after you finished debugging
In eclipse go to the DDMS perspective and in the devices tab click the process you want to kill under the device you want to kill it on. You then just need to press the stop button and it should kill the process.
I'm not sure how you'd do this from the command line tool but there must be a way. Maybe you do it through the adb shell...
pkill NAMEofAPP
Non rooted marshmallow, termux & terminal emulator.

Categories

Resources