Android adb shell

Android adb shell to see the package name, permission, process information

April 25, 2018 14:38:57  Yjnull  Reads 6041

 Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/u014306335/article/details/80079067

adb related commands

  • adb delete system applications: adb shell pm uninstall -k --user 0 包名  (pay attention to risk)
  • adb run the application:adb shell am start -n 包名/包名.活动名
  • adb view the application package name on the phone: adb shell pm list packages
  • Check the installation location of the phone on the apk file: adb shell pm list packages -f
  • View dangerous permissions:adb shell pm list permissions -d -g
  • View process information: adb shell ps or adb shell ps | grep 包名
  • zsh view the current use topic  echo \$ZSH_THEME or  echo $RANDOM_THEME (when using a random theme)

Android various catalogs

Environment.getExternalStorageDirectory() :/storage/emulated/0

Context.getExternalCacheDir() :/storage/emulated/0/Android/data/包名/cache

Context.getFilesDir() :/data/user/0/包名/files

Context.getCacheDir() : / Data / user / 0 / package name / cache

Solution .gitignore rule does not take effect:

To ignore certain directories or files added to the rules, found not taken effect because .gitignore can only ignore the original document is not being tracked, if some files have been included in the version management, modifying .gitignore it is invalid. Then the solution is to first delete the local cache (not track changes to the state), and then submitted to:

    git rm -r --cached <file>
    git add .
    git commit -m ‘message'
  • 1
  • 2
  • 3

The undo operation commit git

    git reset --soft HEAD^
  • 1

This operation reference  git use Scenario 2

 

QQ after the apk file command installed, ready to unload when found by abd shell pm list packages command, finding QQ corresponding package name, do not know why, and then use the output of adb shell pm list packages -3 tripartite packages can be found

adb shell pm list packages [options] <FILTER>

Print all packages, the package can choose to print the package name contains <FILTER> only.

Used without parameters: adb shell pm list packages, all packages on the printing device / simulator

Used without parameters: adb shell pm list packages, all packages on the printing device / simulator

Using the -f parameter: file adb shell pm list packages -f, output packets and packets associated

Use the -d parameter: adb shell pm list packages -d, only the output disabled package. Since the machine is not disabled, the output is empty.

Use the -e parameter: adb shell pm list packages -e, output only enabled package.

-S parameter: adb shell pm list packages -s, the system outputs only the packet.

Use -3 parameters: adb shell pm list packages -3, output only third-party packages.

-I argument: adb shell pm list packages -i, and installation information output only the packet (source installation).

Use -u parameters: adb shell pm list packages -u, and outputs only the packet information has not been installed (installation source).

Use --user parameters: adb shell pm list packages --user <USER_ID>, all packets according to user id space user queries, the USER_ID sequence representative of currently connected devices, scratch:

And using the parameter set filters -e: adb shell pm list packages -e "ximalaya", only the output enable packets.

 

Android application by forcibly shut down and start ADB Shell

October 16, 2018 10:39:23  music free I  read the number 2894

 Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/lindroid/article/details/83069028

1. On a PC via adb shut down / start applications

1) through the connecting device adb connect 192.168.1.XX adb, of course, may be directly connected through the USB; 

2) execute adb shell ps see a list of currently running processes, you can get the name of the process;

3) execute adb shell am force-stop package name can be forced to shut down the process, eg: adb shell am force-stop com.xxx.xxx

      Perform name adb shell am start -n package name / start classes, eg: adb shell am start -n com.xxx.xxx/com.xxx.xxx.SplashActivity 

 

2. in the code:

 
  1. try {

  2. //关闭其他应用

  3. Process exec = Runtime.getRuntime().exec("am force-stop 包名");

  4. //打开其他应用

  5. Process exec = Runtime.getRuntime().exec("am start -n 包名/启动类名称");

  6. if (exec.waitFor() == 0) {

  7. //执行成功

  8. }

  9. } catch (Exception e) {

  10. e.printStackTrace();

  11. }

Which may block the UI thread when Runtime.getRuntime.exec (), it is proposed that the Executive is in the sub-thread;

I can refer to one another: code to simulate physical buttons  https://blog.csdn.net/lindroid/article/details/83062250

Operation process, need permission

 
  1. //允许程序启动其他应用程序

  2. <uses-permission android:name="android.permission.RESTART_PACKAGES"/>

  3. //允许程序调用killBackgroundProcesses(String).方法结束后台进程

  4. <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>

  5. //如果你使用adb connect

  6. <uses-permission android:name="android.permission.INTERNET" />

 

If you want to completely exit the current process

 
  1. int pid = android.os.Process.myPid();

  2. String command = "kill -9 "+ pid;

  3. try {

  4. Runtime.getRuntime().exec(command);

  5. } catch (IOException e) {

  6. e.printStackTrace();

  7. }

 

 
  1. 退出当前应用,并强行回到桌面

  2. Intent startMain = new Intent(context, LoginActivity.class);

  3. startMain.addCategory(Intent.CATEGORY_HOME);

  4. startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

  5. startMain.addCategory(Intent.ACTION_MAIN);

  6. context.startActivity(startMain);

  7. System.exit(0);

 

1. Review process

1

adb shell ps|findstr package

 

2. kill the process

Method 1: Force stop the process APP, APP process does not clear the data generated in the system

1

adb shell am force-stop package

No output after this command is executed, the corresponding phone process has been killed.

Method 2: Stop the APP process and clears all the data generated by this process APP, the equivalent of reset

1

adb shell pm clear package

 

After executing the command output success means that the command is successful, app process is killed, and will clear all data, equivalent to uninstall and reinstall the effect is generally not recommended.

Guess you like

Origin blog.csdn.net/earthwalkerhwattnet/article/details/92077822