I am writing an application for Android 7.1 using .NET MAUI (.NET 6.0) that behaves something like "Nova Launcher" and similar apps. I am stuck on figuring out how to make the app "override" the default Android launcher (when the home button is pressed my app will show instead of the Android launcher app).
The first thing I tried was searching on Google how to set my Android app to behave like a launcher and I found this old blog post which I think is correct because I have seen "android.intent.category.HOME" multiple times already while searching up why my code didn't work and other questions on Stack Overflow (Not limiting myself on .NET MAUI but searching for Java questions aswell), but the AndroidManifest.xml file doesn't work with .NET MAUI because the way the main activity works. Instead of it appearing on the AndroidManifest.xml (Platforms/Android) it is represented on MainActivity.cs (also Platforms/Android). I have tried to override the OnCreate() method and adding
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
base.OnCreate(savedInstanceState, persistentState);
PackageManager.SetComponentEnabledSetting(new ComponentName(this, Class), ComponentEnabledState.Enabled, ComponentEnableOption.DontKillApp); // with and without this line
Intent intent = new Intent(Intent.ActionMain);
intent.AddCategory(Intent.CategoryHome);
intent.AddCategory(Intent.CategoryDefault);
StartActivity(intent);
}
to it but it simply didn't work. Nothing important on device log (I am using an emulator). The last thing I tried before giving up and asking ChatGPT was searching for Java questions and trying to translate the code to C#, but nothing worked. The only thing slightly different I tried was adding a "FakeLauncherActivity" activity that is disabled at default to the AndroidManifest.xml and then reactivating it using this answer's code (that I translated to C#). ChatGPT only caused my app to crash and do nothing