1、安卓代码:(收集应用名称、版本号和包名)
[Java] 纯文本查看 复制代码 private void collectAppInfo() {
PackageManager pm = getActivity().getPackageManager();
List<PackageInfo> list2 = pm.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
List<AppInfoModel> allAppInfoList = new ArrayList<>();
List<AppInfoModel> androidAppInfoList = new ArrayList<>();
List<AppInfoModel> huaweiAppInfoList = new ArrayList<>();
List<AppInfoModel> thirdAppInfoList = new ArrayList<>();
for (PackageInfo packageInfo : list2) {
//得到手机上已经安装的应用的名字,即在AndriodMainfest.xml中的app_name。
String appName = packageInfo.applicationInfo.loadLabel(getActivity().getPackageManager()).toString();
//得到应用所在包的名字,即在AndriodMainfest.xml中的package的值。
String packageName = packageInfo.packageName;
String versionName = packageInfo.versionName;
AppInfoModel appInfo = new AppInfoModel();
appInfo.setAppName(appName);
appInfo.setPackageName(packageName);
appInfo.setVersionName(versionName);
allAppInfoList.add(appInfo);
if(packageName.startsWith("com.android.")) {
androidAppInfoList.add(appInfo);
} else if(packageName.startsWith("com.huawei.")) {
huaweiAppInfoList.add(appInfo);
} else {
thirdAppInfoList.add(appInfo);
}
}
Log.e("ch_test", "安卓应用数量: " + androidAppInfoList.size() + ", 华为应用数量: "
+ huaweiAppInfoList.size() + ", 第三方应用数量: " + thirdAppInfoList.size()
+ ", 所有应用数量: " + allAppInfoList.size());
LogUtils.e("ch_test", new Gson().toJson(thirdAppInfoList));
2、Python利用adb批量导出安装包:
[Python] 纯文本查看 复制代码 def daochu(packageName, outputName):
try:
newCommand = 'adb shell pm path {}'.format(packageName)
# os.system(newCommand)
(status, uploadRes) = subprocess.getstatusoutput(newCommand)
packagePath = str(uploadRes)[8:]
if 'package:' in packagePath:
packagePath = packagePath[0:packagePath.index('package:')-1]
outputPath = './{}.apk'.format(outputName)
newCommand2 = 'adb pull {} {}'.format(packagePath, outputPath)
os.system(newCommand2)
# (status, uploadRes) = subprocess.getstatusoutput(newCommand2)
# print(str(uploadRes))
except Exception as e2:
print(e2)
print("output error: {}".format(packageName))
return
def allDaochu():
os.chdir('/home/xxx/yyy/apk')
data = ''
with open('package.txt', 'r') as f:
data = f.read()
print(data)
jsonData = json.loads(data)
print(len(jsonData))
for index in range(len(jsonData)):
packageName = jsonData[index]['packageName']
appName = jsonData[index]['appName']
versionName = jsonData[index]['versionName']
if ' ' in appName:
appName = appName.replace(' ', '')
# print(appName)
if ' (' in versionName:
versionName = versionName.replace(' (', '[')
# print(versionName)
if ')' in versionName:
versionName = versionName.replace(')', ']')
# print(versionName)
outputName = '{}-{}'.format(appName, versionName)
print('{}: {}'.format(packageName, outputName))
daochu(packageName, outputName)
|