Last active
December 23, 2015 09:09
-
-
Save weitsai/6612261 to your computer and use it in GitHub Desktop.
使用方法如下: php Android2ApkDevices.php 「APK 路徑」 * 必須要把此 App 和 AXMLPrinter2.jar 放在同個目錄
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$devices = explode("\n", shell_exec("adb devices")); | |
$pattern = "/([a-zA-Z0-9]+)\s+device/"; | |
$zip = new ZipArchive; | |
if ($zip->open($argv[1]) === TRUE) { | |
$zip->extractTo('.', 'AndroidManifest.xml'); | |
$zip->close(); | |
} | |
$AndroidManifest = shell_exec("java -jar AXMLPrinter2.jar AndroidManifest.xml"); | |
$AndroidManifest = simplexml_load_string($AndroidManifest); | |
$package = $AndroidManifest->attributes()->package; | |
foreach ($AndroidManifest->application->activity as $activity) { | |
$category = $activity->{'intent-filter'}->category; | |
if ($category != null && | |
$category->attributes('android', true)->name == 'android.intent.category.LAUNCHER' | |
$className = $activity->attributes('android', true)->name; | |
break; | |
} | |
} | |
for ($i = 1; $i < count($devices); $i++) { | |
if (preg_match("/device$/", $devices[$i])) { | |
// 裝置編號 | |
$deviceNum = preg_replace($pattern, "$1", $devices[$i]); | |
echo "----------" . $deviceNum . "----------\n"; | |
// 安裝 apk 到指定手機 | |
echo shell_exec("adb -s $deviceNum install -r $argv[1]"); | |
// 在特定手機上執行特定程式 | |
$adbStartAppShell = "adb -s $deviceNum shell am start -a android.intent.action.MAI | |
echo shell_exec("$adbStartAppShell"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment