package se.blunden.xbmclauncher;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity {
	
	private static final String TAG = "XBMCLauncher";
	private String xbmcActivity; 
	
	private void launch()
	{
		// Load preferences
		SharedPreferences settings;
		settings = getSharedPreferences("se.blunden.xbmclauncher_preferences", Context.MODE_PRIVATE);
		
		xbmcActivity = settings.getString("xbmc_variant", getString(R.string.xbmc_activity_default));
		
		Intent activityIntent;
		
		// Intent.makeMainActivity is only available in API level 11 and above
		if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
			activityIntent = Intent.makeMainActivity(ComponentName.unflattenFromString(xbmcActivity));
		} else {
			activityIntent = new Intent(Intent.ACTION_MAIN);
            activityIntent.setComponent(ComponentName.unflattenFromString(xbmcActivity));
            activityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
		}
		
		try {
			startActivity(activityIntent);
			return;
		}
		catch (ActivityNotFoundException e)
		{
			Log.d(TAG, "Activity " + xbmcActivity + " not found. Launching settings activity...");
			
			Intent launchSettings = new Intent(this, LauncherSettingsActivity.class);
			startActivity(launchSettings);
		}
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		launch();
		finish();
	}
}

@@ -261,34 +261,8 @@
 s;%0D%0A
-import android.os.Build;%0D%0A
 impo
@@ -280,24 +280,24 @@
 os.Bundle;%0D%0A
+
 import andro
@@ -738,284 +738,79 @@
 %0D%0A%09%09
-Intent activityIntent;%0D%0A%09%09%0D%0A%09%09// Intent.makeMainActivity is only available in API level 11 and above%0D%0A%09%09if(Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.HONEYCOMB) %7B%0D%0A%09%09%09activityIntent = Intent.makeMainActivity(ComponentName.unflattenFromString(xbmcActivity));%0D%0A%09%09%7D else %7B%0D%0A%09%09%09
+// Build the Kodi/XBMC intent%0D%0A        Intent activityIntent;%0D%0A        
 acti
@@ -851,28 +851,24 @@
 ION_MAIN);%0D%0A
-    
         acti
@@ -942,24 +942,214 @@
 ity));%0D%0A    
+    /*%0D%0A         * The launched activity will be considered the HOME activity and will be on top of the%0D%0A         * stack as needed for the system to broadcast BOOT_COMPLETED.%0D%0A         */%0D%0A
         acti
@@ -1191,23 +1191,14 @@
 ORY_
-LAUNCHER);%0D%0A%09%09%7D
+HOME);
 %0D%0A%09%09

Fix the issue with BOOT_COMPLETED not being sent when set as launcher