问题
I am using an FOR command and AAPT command to get a package name from a number of APKs in a directory. I am using a separate FOR command and ADB command to list all of the 3rd party installed applications from the device.
I am unsure how to cross reference these to get the output I would like. I am trying to see if any of the contents of of the AAPT command appears in the the output of the ADB command. If the 2 variables match, do nothing. Otherwise, if the AAPT does not match any of the ADB outputs, show the package name from the AAPT command for that loop.
I hope you can understand what I am trying to achieve. Please see my attempt below:
::Global
@echo off
set AAPT=tools\aapt.exe
set GREP=tools\grep.exe
set CUT=tools\cut.exe
:: Applications
cls
@echo.
@echo ------------------------ CHECK APPLICATIONS INSTALLED --------------------------
SETLOCAL ENABLEDELAYEDEXPANSION
@echo -- EXTRACT PACKAGENAME FROM APK --
FOR /F "tokens=1,2 skip=1" %%N IN ('adb devices') DO (
SET IS_DEV=%%O
if "!IS_DEV!" == "device" (
SET SERIAL=%%N
for /f "delims=" %%P in ('dir /b ^"APKs\*.apk^"') do (
SET APK=%%P
for /f "tokens=1 delims=" %%Q in ('%AAPT% d badging APKs\!APK! ^| !GREP! "package: name=" ^| !CUT! -d' -f2') do (
set package=%%Q
if "!package!" == "" set package=Unknown (
echo !package!
)
)
)
)
)
@echo.
@echo -- EXTRACT INSTALLED PACKAGENAME --
FOR /F "tokens=1,2 skip=1" %%R IN ('adb devices') DO (
if "!IS_DEV!" == "device" (
FOR /F "tokens=1 delims=" %%U IN ('adb shell "pm list packages -3" ^| !CUT! -f 2 -d ":"^') DO (
SET DEVPACKAGE=%%U
echo !DEVPACKAGE!
)
)
)
)
)
@echo.
@echo -- CHECK IF ALL "DEVPACKAGE" MATCHES "PACKAGE" AND LOOP --
for /f "delims=" %%S in ('dir /b ^"APKs\*.apk^"') do (
if "!package:*%DEVPACKAGE%=!" neq "!package!" (
echo !package! matched
) else (
echo !package! did not match
)
)
ENDLOCAL
@pause
The output I am receiving is:
------------------------ CHECK APPLICATIONS INSTALLED --------------------------
-- EXTRACT PACKAGENAME FROM APK --
com.microsoft.office.lync15
com.microsoft.office.officehub
com.yammer.v1
com.teslacoilsw.launcher
yes.worldpaytotal
com.yahoo.mobile.client.android.weather
-- EXTRACT INSTALLED PACKAGENAME --
com.yahoo.mobile.client.android.weather
de.worldiety.photiety.cewe.smartphoto.de
com.estrongs.android.pop
com.yammer.v1
de.zalando.mobile
com.microsoft.office.officehub
de.kaufda.android
com.microsoft.office.lync15
com.kronos.mobile.android
com.manageengine.adssp.passwordselfservice
com.teslacoilsw.launcher
yes.worldpaytotal
-- CHECK IF ALL "DEVPACKAGE" MATCHES "PACKAGE" AND LOOP --
com.yahoo.mobile.client.android.weather did not match
com.yahoo.mobile.client.android.weather did not match
com.yahoo.mobile.client.android.weather did not match
com.yahoo.mobile.client.android.weather did not match
com.yahoo.mobile.client.android.weather did not match
com.yahoo.mobile.client.android.weather did not match
Press any key to continue . . .
If anyone is able to help, I would greatly appreciate it!
来源:https://stackoverflow.com/questions/42815229/windows-batch-adb-check-if-installed-apk-matches-apk-from-a-directory