first we need set KODI as Launcher for Android so we need these changes:
you can do this with this helper text.
MODIFY ANDROIDMANIFEST.XML.IN TO MAKE KODI DETECTED AS A LAUNCHER
Modify tools/android/packaging/xbmc/AndroidManifest.xml.in
to make Kodi a launcher so that:
Launcher intent filter is added to Main activity:
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>
Splash and Main activities have android:launchMode="singleTop"
Splash and Main activities have android:documentLaunchMode="never"
Splash and Main activities have android:excludeFromRecents="true"
The developer guidelines suggest setting android:launchMode="singleTask" and androidConfusedtateNotNeeded="true" for launchers but this causes significant load times (as it starts from scratch every time you go to the home screen) and I have found no issues running with singleTop and no stateNotNeeded.
MODIFY XBMCAPP.CPP TO CATCH HOME BUTTON INTENT
To react to "Home button press" add handling for android.intent.action.MAIN/android.intent.category.HOME in void CXBMCApp::onNewIntent(CJNIIntent intent) (found on line 1076 in xbmc/platform/android/activity/XBMCApp.cpp):
if(action == "android.intent.action.MAIN" && intent.hasCategory("android.intent.category.HOME")) { CApplicationMessenger::GetInstance().PostMsg(TMSG_GUI_ACTIVATE_WINDOW, WINDOW_HOME, 0, nullptr); // Sets Home window as active } else // below is original code if (!targetFile.empty() && (action == "android.intent.action.VIEW" || action == "android.intent.action.GET_CONTENT")) { CLog::Log(LOGDEBUG, "-- targetFile: %s", targetFile.c_str()); ...
The above will send Kodi to Home.xml when the Home button is pressed (the key press doesn't generate a key press event, it only generates a MAIN/HOME intent). One could look at clearing the "Kodi window stack" as well (so that back button press after pressing home goes nowhere).