adb命令实现一些有趣的功能
下載ADB工具集,手機(jī)連接電腦后,用Windows自帶命令行進(jìn)入ADB工具,輸入以下命令即可免root實(shí)現(xiàn)神奇功能
1.電量顯示:
adb shell content insert --uri content://settings/system --bind name:s:status_bar_show_battery_percent --bind value:i:12.全屏沉浸:
adb shell settings put global policy_control immersive.full=*3.沉浸狀態(tài)欄:
adb shell settings put global policy_control immersive.status=*4.沉浸導(dǎo)航欄:
adb shell settings put global policy_control immersive.navigation=*5.我們還可以單獨(dú)控制哪些app不沉浸,例如以下代碼設(shè)置google即時桌面不沉浸,其他程序沉浸:
adb shell settings put global policy_control immersive.full=apps,-com.google.android.googlequicksearchbox6.如果想恢復(fù)到正常模式,運(yùn)行下面的代碼:
adb shell settings put global policy_control null7.截圖命令screencap
adb shell screencap -p /sdcard/screen.png8.命令行下拉和收縮狀態(tài)欄
adb shell service call statusbar 1 //下拉顯示命令行 adb shell service call statusbar 2 //收縮狀態(tài)欄在nexus6吧發(fā)現(xiàn)了上面這個帖子,感謝nexus6吧的機(jī)友,親測可用,很強(qiáng)大,可以正常使用輸入法,使用虛擬按鍵時從底部上滑即可,比貼吧里那個使用全能助手隱藏虛擬鍵的方法好些,adb工具用刷機(jī)精靈也可以,我是把第四條和第五條命令綜合一下,nova啟動器不隱藏虛擬鍵,其他全部隱藏虛擬鍵,但狀態(tài)欄都不隱藏,指令:
adb shell settings put global policy_control immersive.navigation=apps,-com.teslacoilsw.launcheradb shell settings put global policy_control immersive.navigation=apps,-com.teslacoilsw.launcher,-com.motorola.camera由于機(jī)友反映打開相機(jī)無法呼出虛擬鍵,今天把指令改進(jìn)了一下,這個adb指令可以讓nova啟動器和moto相機(jī)都不隱藏虛擬鍵,從而解決了隱藏虛擬鍵后打開相機(jī)上滑無法呼出虛擬鍵。
moto z/z play按一下指紋鍵就可以自動呼出虛擬鍵,不用上滑呼出的,所以,這種方法還是可以的,不用root,不影響OTA和保修。
(注意:1.adb工具也可以下載刷機(jī)精靈,使用其工具中的adb命令行;2.輸入adb命令時記得切換到英文;3.apps后面的文件名,可以在手機(jī)上打開,然后去設(shè)置中的正在運(yùn)行的程序中查看,或者下載安裝文件名查看器查看 )
adb shell am 的用法
C:\Users\Administrator>adb shell am usage: am [subcommand] [options]start an Activity: am start [-D] [-W] <INTENT>-D: enable debugging-W: wait for launch to completestart a Service: am startservice <INTENT>send a broadcast Intent: am broadcast <INTENT>start an Instrumentation: am instrument [flags] <COMPONENT>-r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)-e <NAME> <VALUE>: set argument <NAME> to <VALUE>-p <FILE>: write profiling data to <FILE>-w: wait for instrumentation to finish before returningstart profiling: am profile <PROCESS> start <FILE> stop profiling: am profile <PROCESS> stopstart monitoring: am monitor [--gdb <port>]--gdb: start gdbserv on the given port at crash/ANR<INTENT> specifications include these flags:[-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>][-c <CATEGORY> [-c <CATEGORY>] ...][-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...][--esn <EXTRA_KEY> ...][--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...][-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...][-n <COMPONENT>] [-f <FLAGS>][--grant-read-uri-permission] [--grant-write-uri-permission][--debug-log-resolution][--activity-brought-to-front] [--activity-clear-top][--activity-clear-when-task-reset] [--activity-exclude-from-recents][--activity-launched-from-history] [--activity-multiple-task][--activity-no-animation] [--activity-no-history][--activity-no-user-action] [--activity-previous-is-top][--activity-reorder-to-front] [--activity-reset-task-if-needed][--activity-single-top][--receiver-registered-only] [--receiver-replace-pending][<URI>]使用實(shí)例:
如啟動一個 Activity:
格式:
adb shell am start -n 包名/包名+類名(-n 類名,-a action,-d date,-m MIME-TYPE,-c category,-e 擴(kuò)展數(shù)據(jù),等)。實(shí)例1:
C:\Users\Administrator>adb shell am start -n com.android.camera/.Camera Starting: Intent { cmp=com.android.camera/.Camera }實(shí)例2:(帶extra 的 intent)
C:\Users\Administrator>adb shell am start -n com.android.camera/.Camera -e abc helloStarting: Intent { cmp=com.android.camera/.Camera (has extras) }
其中 extra 的 key 為 abc ,value 為字串 "hello"
還可以發(fā)送命令模擬手機(jī)低電環(huán)境:
實(shí)例:
ANDROID: 設(shè)置顯示窗口的SIZE和DENSITY
Android系統(tǒng)中有一個wm命令,可以設(shè)置顯示窗口的尺寸(重新設(shè)置屏幕的羅輯分辯率)和屏幕的dpi。
設(shè)置顯示窗口的尺寸
$ adb shell wm size 540x960顯示窗口的尺寸可以比屏幕的物理分辨率大,也可以比它小。重置用如下命令:
$ adb shell wm size reset設(shè)置完之后,你會發(fā)現(xiàn)SurfaceFlinger中的Layer的尺寸也發(fā)生的變化。
以Nexus4為例,原來Live Wallpaper: PhaseBeam Layer的尺寸為768×1280:
將顯示窗口的尺寸設(shè)為1080×1920之后:
$ adb shell dumpsys SurfaceFlinger ... + Layer 0xb7d596b8 (com.android.phasebeam.PhaseBeamWallpaper)Region transparentRegion (this=0xb7d59818, count=1)[ 0, 0, 0, 0]Region visibleRegion (this=0xb7d596c0, count=1)[ 0, 50, 1080, 1824]layerStack= 0, z= 21000, pos=(0,0), size=(1080,1920), crop=( 0, 50,1080,1824), isOpaque=1, invalidate=0, alpha=0xff, flags=0x00000002, tr=[1.00, 0.00][0.00, 1.00]client=0xb7dbf270format= 2, activeBuffer=[1080x1920:1152, 3], queued-frames=0, mRefreshPending=0mTexName=10 mCurrentTexture=2mCurrentCrop=[0,0,0,0] mCurrentTransform=0mAbandoned=0-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[1080x1920], default-format=2, transform-hint=00, FIFO(0)={}[00:0xb7dd1fb0] state=FREE , 0xb7dd0048 [1080x1920:1152, 3][01:0xb7d5c2c8] state=FREE , 0xb7d39ca8 [1080x1920:1152, 3]>[02:0xb7d1d578] state=ACQUIRED, 0xb7d5cb18 [1080x1920:1152, 3] ...可以想象得到,系統(tǒng)把這個layer對應(yīng)的窗口當(dāng)成了一個1080p屏幕來布局和繪制了。
設(shè)置屏幕的dpi
Android 將實(shí)際屏幕尺寸和密度的范圍 分為:
1.四種通用尺寸:小、正常、 大 和超大
2.六種通用的密度:
- ldpi(低)~120dpi
- mdpi(中)~160dpi
- hdpi(高)~240dpi
- xhdpi(超高)~320dpi
- xxhdpi(超超高)~480dpi
-
xxxhdpi(超超超高)~640dpi
?
常用的dpi有160(mdpi), 240(hdpi), 320(xhdpi), 480(xxhdpi)。重置可用如下命令:
$ adb shell wm density reset如何實(shí)現(xiàn) ,以設(shè)置顯示窗口尺寸為例(@android-5.1.1)
首先看一下wm命令如何通知WindowManagerService更新配置:
代碼:frameworks/base/cmds/wm/src/com/android/commands/wm/Wm.java
先獲取WindowManagerService再調(diào)用它的setForcedDisplaySize()方法。
代碼:frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
這里可以看到可以設(shè)置的屏幕窗口最小為(200,200),最大小顯示屏分辨率的兩倍。
而WindowManagerService又是如何通知DisplayManagerService更新配置:
到這里就會去設(shè)置layer stack的尺寸和在屏幕上的位置:
final class LogicalDisplay {.../*** Applies the layer stack and transformation to the given display device* so that it shows the contents of this logical display.** We know that the given display device is only ever showing the contents of* a single logical display, so this method is expected to blow away all of its* transformation properties to make it happen regardless of what the* display device was previously showing.** The caller must have an open Surface transaction.** The display device may not be the primary display device, in the case* where the display is being mirrored.** @param device The display device to modify.* @param isBlanked True if the device is being blanked.*/public void configureDisplayInTransactionLocked(DisplayDevice device,boolean isBlanked) {final DisplayInfo displayInfo = getDisplayInfoLocked();final DisplayDeviceInfo displayDeviceInfo = device.getDisplayDeviceInfoLocked();// Set the layer stack.device.setLayerStackInTransactionLocked(isBlanked ? BLANK_LAYER_STACK : mLayerStack);// Set the refresh ratedevice.requestRefreshRateLocked(mRequestedRefreshRate);// Set the viewport.// This is the area of the logical display that we intend to show on the// display device. For now, it is always the full size of the logical display.mTempLayerStackRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);// Set the orientation.// The orientation specifies how the physical coordinate system of the display// is rotated when the contents of the logical display are rendered.int orientation = Surface.ROTATION_0;if ((displayDeviceInfo.flags & DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT) != 0) {orientation = displayInfo.rotation;}// Apply the physical rotation of the display device itself.orientation = (orientation + displayDeviceInfo.rotation) % 4;// Set the frame.// The frame specifies the rotated physical coordinates into which the viewport// is mapped. We need to take care to preserve the aspect ratio of the viewport.// Currently we maximize the area to fill the display, but we could try to be// more clever and match resolutions.boolean rotated = (orientation == Surface.ROTATION_90|| orientation == Surface.ROTATION_270);int physWidth = rotated ? displayDeviceInfo.height : displayDeviceInfo.width;int physHeight = rotated ? displayDeviceInfo.width : displayDeviceInfo.height;// Determine whether the width or height is more constrained to be scaled.// physWidth / displayInfo.logicalWidth => letter box// or physHeight / displayInfo.logicalHeight => pillar box//// We avoid a division (and possible floating point imprecision) here by// multiplying the fractions by the product of their denominators before// comparing them.int displayRectWidth, displayRectHeight;if (physWidth * displayInfo.logicalHeight< physHeight * displayInfo.logicalWidth) {// Letter box.displayRectWidth = physWidth;displayRectHeight = displayInfo.logicalHeight * physWidth / displayInfo.logicalWidth;} else {// Pillar box.displayRectWidth = displayInfo.logicalWidth * physHeight / displayInfo.logicalHeight;displayRectHeight = physHeight;}int displayRectTop = (physHeight - displayRectHeight) / 2;int displayRectLeft = (physWidth - displayRectWidth) / 2;mTempDisplayRect.set(displayRectLeft, displayRectTop,displayRectLeft + displayRectWidth, displayRectTop + displayRectHeight);device.setProjectionInTransactionLocked(orientation, mTempLayerStackRect, mTempDisplayRect);}... }->DisplayDevice.setProjectionInTransactionLocked()
通知SurfaceFlinger:
最后,SurfaceFlinger就會跟據(jù)這些信息對Layer進(jìn)行合成,顯示在屏幕上。
代碼:frameworks/native/services/surfaceflinger/DisplayDevice.cpp
aapt命令獲取apk詳細(xì)信息(包名、版本號、版本名稱、兼容api級別、啟動Activity等)
找到sdk的根目錄,然后找到build-tools文件夾,然后會看到一些build-tools的版本號,隨便點(diǎn)開一個,就可以看到aapt
?獲取apk的詳細(xì)信息
aapt dump badging app-debug.apk
? ??
作者:xmaihh
鏈接:https://www.jianshu.com/p/5c2bf91b1ff8
來源:簡書
簡書著作權(quán)歸作者所有,任何形式的轉(zhuǎn)載都請聯(lián)系作者獲得授權(quán)并注明出處。
總結(jié)
以上是生活随笔為你收集整理的adb命令实现一些有趣的功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android PC投屏简单尝试—最终章
- 下一篇: Android P 图形显示系统