Skip to content

Instantly share code, notes, and snippets.

@Lachee
Created December 7, 2018 08:09
Show Gist options
  • Save Lachee/12315bf6a7ff8f2374fb7789bdc6b2d0 to your computer and use it in GitHub Desktop.
Save Lachee/12315bf6a7ff8f2374fb7789bdc6b2d0 to your computer and use it in GitHub Desktop.
Will install APK files onto hte android device and then immediately run them
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ApkRun
{
class Program
{
static void Main(string[] args)
{
string apk = args[0];
Console.WriteLine("Installing APK: {0}", apk);
var installProcess = Process.Start("adb", "install -r \"" + apk + "\"");
installProcess.WaitForExit();
Console.WriteLine("Running...");
var runProcess = new Process()
{
StartInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Android\android-sdk\build-tools\23.0.1\aapt.exe", "dump badging \"" + apk + "\"")
{
RedirectStandardOutput = true,
UseShellExecute = false
}
};
runProcess.Start();
string result = runProcess.StandardOutput.ReadToEndAsync().Result;
string package = "";
string activity = "com.unity3d.player.UnityPlayerActivity";
string[] lines = result.Split('\n');
Regex packageRegex = new Regex("package: name='(.*)' versionCode");
foreach (var l in lines)
{
var match = packageRegex.Match(l);
if (match.Success)
{
if (l.Contains("package:"))
{
package = match.Groups[1].ToString();
}
}
}
Console.WriteLine("Package: " + package);
Console.WriteLine("Activity: " + activity);
//adb shell am start -n $pkg/$act
string runargs = "shell am start " + package + "/" + activity;
Console.WriteLine("Running...");
var actualRunProcess = new Process()
{
StartInfo = new ProcessStartInfo("adb", runargs)
{
RedirectStandardOutput = true,
UseShellExecute = false
}
};
actualRunProcess.Start();
actualRunProcess.WaitForExit();
string actualRunResult = runProcess.StandardOutput.ReadToEndAsync().Result;
Console.WriteLine("Finished Executing!");
Console.WriteLine(actualRunResult);
if (!string.IsNullOrWhiteSpace(actualRunResult))
Console.ReadKey();
}
}
}
/*
package: name='com.UTAS.Unity.Jack' versionCode='1' versionName='1.0' platformBuildVersionName=''
launchable-activity: name='com.unity3d.player.UnityPlayerActivity' label='AR Textbook' icon=''
install-location:'preferExternal'
sdkVersion:'16'
targetSdkVersion:'26'
uses-permission: name='android.permission.INTERNET'
uses-permission: name='android.permission.CAMERA'
uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
application-label:'AR Textbook'
application-label-fil:'AR Textbook'
application-label-gsw:'AR Textbook'
application-label-ca:'AR Textbook'
application-label-da:'AR Textbook'
application-label-fa:'AR Textbook'
application-label-ja:'AR Textbook'
application-label-ka:'AR Textbook'
application-label-pa:'AR Textbook'
application-label-ta:'AR Textbook'
application-label-nb:'AR Textbook'
application-label-id:'AR Textbook'
application-label-be:'AR Textbook'
application-label-de:'AR Textbook'
application-label-he:'AR Textbook'
application-label-ne:'AR Textbook'
application-label-te:'AR Textbook'
application-label-af:'AR Textbook'
application-label-bg:'AR Textbook'
application-label-th:'AR Textbook'
application-label-zh:'AR Textbook'
application-label-fi:'AR Textbook'
application-label-hi:'AR Textbook'
application-label-si:'AR Textbook'
application-label-vi:'AR Textbook'
application-label-kk:'AR Textbook'
application-label-mk:'AR Textbook'
application-label-sk:'AR Textbook'
application-label-uk:'AR Textbook'
application-label-el:'AR Textbook'
application-label-gl:'AR Textbook'
application-label-ml:'AR Textbook'
application-label-nl:'AR Textbook'
application-label-pl:'AR Textbook'
application-label-sl:'AR Textbook'
application-label-tl:'AR Textbook'
application-label-am:'AR Textbook'
application-label-km:'AR Textbook'
application-label-bn:'AR Textbook'
application-label-in:'AR Textbook'
application-label-kn:'AR Textbook'
application-label-mn:'AR Textbook'
application-label-ko:'AR Textbook'
application-label-lo:'AR Textbook'
application-label-mo:'AR Textbook'
application-label-no:'AR Textbook'
application-label-ro:'AR Textbook'
application-label-sq:'AR Textbook'
application-label-fr:'AR Textbook'
application-label-hr:'AR Textbook'
application-label-sr:'AR Textbook'
application-label-sr-Latn:'AR Textbook'
application-label-tr:'AR Textbook'
application-label-ur:'AR Textbook'
application-label-bs:'AR Textbook'
application-label-cs:'AR Textbook'
application-label-es:'AR Textbook'
application-label-is:'AR Textbook'
application-label-ms:'AR Textbook'
application-label-et:'AR Textbook'
application-label-it:'AR Textbook'
application-label-lt:'AR Textbook'
application-label-pt:'AR Textbook'
application-label-eu:'AR Textbook'
application-label-gu:'AR Textbook'
application-label-hu:'AR Textbook'
application-label-ru:'AR Textbook'
application-label-zu:'AR Textbook'
application-label-lv:'AR Textbook'
application-label-sv:'AR Textbook'
application-label-iw:'AR Textbook'
application-label-sw:'AR Textbook'
application-label-hy:'AR Textbook'
application-label-ky:'AR Textbook'
application-label-my:'AR Textbook'
application-label-az:'AR Textbook'
application-label-uz:'AR Textbook'
application-label-es-419:'AR Textbook'
application-label-en-CA:'AR Textbook'
application-label-fr-CA:'AR Textbook'
application-label-es-PA:'AR Textbook'
application-label-ar-SA:'AR Textbook'
application-label-en-XA:'AR Textbook'
application-label-en-ZA:'AR Textbook'
application-label-en-GB:'AR Textbook'
application-label-ar-XB:'AR Textbook'
application-label-es-EC:'AR Textbook'
application-label-en-XC:'AR Textbook'
application-label-en-IE:'AR Textbook'
application-label-es-PE:'AR Textbook'
application-label-es-VE:'AR Textbook'
application-label-ar-EG:'AR Textbook'
application-label-en-SG:'AR Textbook'
application-label-de-CH:'AR Textbook'
application-label-fr-CH:'AR Textbook'
application-label-es-NI:'AR Textbook'
application-label-zh-HK:'AR Textbook'
application-label-es-CL:'AR Textbook'
application-label-zh-CN:'AR Textbook'
application-label-es-HN:'AR Textbook'
application-label-es-BO:'AR Textbook'
application-label-es-CO:'AR Textbook'
application-label-es-DO:'AR Textbook'
application-label-es-AR:'AR Textbook'
application-label-pt-BR:'AR Textbook'
application-label-es-CR:'AR Textbook'
application-label-es-PR:'AR Textbook'
application-label-es-US:'AR Textbook'
application-label-de-AT:'AR Textbook'
application-label-es-GT:'AR Textbook'
application-label-pt-PT:'AR Textbook'
application-label-en-AU:'AR Textbook'
application-label-es-SV:'AR Textbook'
application-label-zh-TW:'AR Textbook'
application-label-es-MX:'AR Textbook'
application-label-es-PY:'AR Textbook'
application-label-es-UY:'AR Textbook'
application-icon-160:'res/mipmap-anydpi-v26/app_icon.xml'
application-icon-320:'res/mipmap-anydpi-v26/app_icon.xml'
application-icon-65534:'res/mipmap-anydpi-v26/app_icon.xml'
application: label='AR Textbook' icon='res/mipmap-anydpi-v26/app_icon.xml' banner='res/drawable-xhdpi-v4/app_banner.png'
application-isGame
uses-library-not-required:'com.osterhoutgroup.api.ext'
feature-group: label=''
uses-gl-es: '0x20000'
uses-feature: name='android.hardware.camera'
uses-feature-not-required: name='android.hardware.camera.autofocus'
uses-feature-not-required: name='android.hardware.camera.front'
uses-feature-not-required: name='android.hardware.touchscreen'
uses-feature-not-required: name='android.hardware.touchscreen.multitouch'
uses-feature-not-required: name='android.hardware.touchscreen.multitouch.distinct'
uses-feature: name='android.hardware.screen.portrait'
uses-implied-feature: name='android.hardware.screen.portrait' reason='one or more activities have specified a portrait orientation'
main
other-activities
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--' 'fil' 'gsw' 'ca' 'da' 'fa' 'ja' 'ka' 'pa' 'ta' 'nb' 'id' 'be' 'de' 'he' 'ne' 'te' 'af' 'bg' 'th' 'zh' 'fi' 'hi' 'si' 'vi' 'kk' 'mk' 'sk' 'uk' 'el' 'gl' 'ml' 'nl' 'pl' 'sl' 'tl' 'am' 'km' 'bn' 'in' 'kn' 'mn' 'ko' 'lo' 'mo' 'no' 'ro' 'sq' 'fr' 'hr' 'sr' 'sr-Latn' 'tr' 'ur' 'bs' 'cs' 'es' 'is' 'ms' 'et' 'it' 'lt' 'pt' 'eu' 'gu' 'hu' 'ru' 'zu' 'lv' 'sv' 'iw' 'sw' 'hy' 'ky' 'my' 'az' 'uz' 'es-419' 'en-CA' 'fr-CA' 'es-PA' 'ar-SA' 'en-XA' 'en-ZA' 'en-GB' 'ar-XB' 'es-EC' 'en-XC' 'en-IE' 'es-PE' 'es-VE' 'ar-EG' 'en-SG' 'de-CH' 'fr-CH' 'es-NI' 'zh-HK' 'es-CL' 'zh-CN' 'es-HN' 'es-BO' 'es-CO' 'es-DO' 'es-AR' 'pt-BR' 'es-CR' 'es-PR' 'es-US' 'de-AT' 'es-GT' 'pt-PT' 'en-AU' 'es-SV' 'zh-TW' 'es-MX' 'es-PY' 'es-UY'
densities: '160' '320' '65534'
native-code: 'armeabi-v7a'
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment