Skip to content

Commit 8f67b75

Browse files
ComputerEliteComputerElite
authored andcommitted
add file picker for apk installs
1 parent f97e36c commit 8f67b75

5 files changed

Lines changed: 47 additions & 2 deletions

File tree

QuestAppVersionSwitcher/Assets/html/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ <h2>Downloads</h2>
254254
<div class="buttonLabel">Disables and deletes all mods from the currently selected game</div>
255255
</div>
256256
<div class="buttonContainer">
257-
<div class="button" id="uninstallBS">Uninstall Beat Saber</div>
258-
<div class="buttonLabel">Experimental way to fix the ghost Beat Saber issue</div>
257+
<div class="button" onclick="InstallAPKFromDisk()">Install apk from disk</div>
258+
<div class="buttonLabel">Opens a file picker to install any apk on your quest</div>
259259
</div>
260260
<div id="updateTextBox" class="textBox"></div>
261261

QuestAppVersionSwitcher/Assets/html/script.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,11 @@ function CheckStartParams() {
604604
}
605605
}
606606

607+
/*
607608
document.getElementById("uninstallBS").onclick = () => {
608609
fetch("/api/android/uninstallpackage?package=com.beatgames.beatsaber&force=true", {method: "POST"})
609610
}
611+
*/
610612

611613
var config = {}
612614
var selectedBackup = ""
@@ -694,6 +696,10 @@ function UpdateUI(closeLists = false) {
694696
UpdatePatchingStatus()
695697
}
696698

699+
function InstallAPKFromDisk() {
700+
fetch("/api/android/installapkfromdisk", {method: "POST"})
701+
}
702+
697703
document.getElementById("login").onclick = () => {
698704
if(!IsOnQuest()) return;
699705
OpenGetPasswordPopup()

QuestAppVersionSwitcher/CoreService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
using ComputerUtils.Android;
1212
using Newtonsoft.Json;
1313
using JsonSerializer = System.Text.Json.JsonSerializer;
14+
using Object = Java.Lang.Object;
1415

1516
namespace QuestAppVersionSwitcher.Core
1617
{
1718
public class CoreService
1819
{
20+
public static MainActivity mainActivity;
1921
public static WebView browser = null;
2022
public static QAVSWebserver qAVSWebserver = new QAVSWebserver();
2123
public static CoreVars coreVars = new CoreVars();

QuestAppVersionSwitcher/MainActivity.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
using QuestAppVersionSwitcher.Core;
1515
using System.IO;
1616
using Android.Content;
17+
using Android.Database;
1718
using Android.Provider;
1819
using AndroidX.Activity.Result.Contract;
20+
using ComputerUtils.Android.AndroidTools;
21+
using ComputerUtils.Android.Webserver;
1922
using AlertDialog = Android.App.AlertDialog;
2023

2124
namespace QuestAppVersionSwitcher
2225
{
2326
[Activity(Theme = "@style/AppTheme", ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
2427
public class MainActivity : AppCompatActivity
2528
{
29+
public static int pickFileCode = 1;
2630
WebView webView;
2731
protected override void OnCreate(Bundle savedInstanceState)
2832
{
@@ -33,6 +37,7 @@ protected override void OnCreate(Bundle savedInstanceState)
3337
SetContentView(Resource.Layout.activity_main);
3438
//Get webView WebView from Main Layout
3539
webView = FindViewById<WebView>(Resource.Id.webView);
40+
CoreService.mainActivity = this;
3641

3742
CoreVars.fileDir = "/sdcard/Android/data/com.ComputerElite.questappversionswitcher/files/";
3843
CoreService.browser = webView;
@@ -48,6 +53,29 @@ protected override void OnCreate(Bundle savedInstanceState)
4853
CoreService.Start();
4954
}
5055

56+
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
57+
{
58+
if (requestCode == pickFileCode && resultCode == Result.Ok)
59+
{
60+
// Get the URI of the selected file
61+
Android.Net.Uri uri = data.Data;
62+
Logger.Log(uri.ToString());
63+
64+
// Convert the URI to a file path
65+
string path = GetRealPathFromURI(uri);
66+
67+
// Start apk install
68+
Logger.Log("Selected apk for installation: " + path);
69+
AndroidService.InitiateInstallApk(path);
70+
}
71+
}
72+
73+
private string GetRealPathFromURI(Android.Net.Uri uri)
74+
{
75+
return HttpServer.DecodeUrlString(uri.ToString()
76+
.Replace("content://com.android.externalstorage.documents/document/primary%3A", "/sdcard/"));
77+
}
78+
5179
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
5280
{
5381
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

QuestAppVersionSwitcher/WebServer.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,15 @@ public void Start()
855855

856856
serverRequest.SendString(GenericResponse.GetResponse("uploaded and selected app in backup tab", true), "application/json");
857857
return true;
858+
});
859+
server.AddRoute("POST", "/api/android/installapkfromdisk", serverRequest => {
860+
Intent chooseFile = new Intent(Intent.ActionGetContent);
861+
chooseFile.SetType("application/vnd.android.package-archive");
862+
chooseFile = Intent.CreateChooser(chooseFile, "Choose an apk to install");
863+
Logger.Log("Opening file picker for apk install");
864+
CoreService.mainActivity.StartActivityForResult(chooseFile, MainActivity.pickFileCode);
865+
serverRequest.SendString(GenericResponse.GetResponse("Opened file picker", true), "application/json");
866+
return true;
858867
});
859868
server.AddRoute("GET", "/api/backups", serverRequest =>
860869
{

0 commit comments

Comments
 (0)