Android Question How to create a launcher app

wimpie3

Well-Known Member
Licensed User
Longtime User
I'm building a kiosk with only one app on it, and I don't want the standard launcher to appear when Android boots up. I know you can create an autostart program by using a service, but that still shows the standard launcher FIRST. I want to HIDE that completely. Creating an empty (blank) launcher could be a solution, but CAN you write a launcher in B4A?
 

wimpie3

Well-Known Member
Licensed User
Longtime User
OK, found this in the meanwhile ;-) However, it seems you can lock yourself out if you create a homescreen without icons... is there a shortcut to launch the homescreen selection menu even if that icon isn't visible on the homescreen?
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
With the device connected via usb you can remotely uninstall any app:

B4X:
adb uninstall <packagenamehere>

So that'll save you if your launcher locks you out.
 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
Can I launch the homescreen selection intent to let the user select another homescreen (for instance, after giving the correct password)? How would I do that?
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
You can experiment with the below java - add it to your project as inline java.

B4X:
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import anywheresoftware.b4a.BA;

public static void ResetDefaultLauncher(BA pBA, String PackageName, String ClassName) {
	Context mContext = pBA.context;
	PackageManager pm = mContext.getPackageManager();
	ComponentName mockupComponent = new ComponentName(PackageName, ClassName);

	pm.setComponentEnabledSetting(mockupComponent, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

	Intent startMain = new Intent(Intent.ACTION_MAIN);
	startMain.addCategory(Intent.CATEGORY_HOME);
	startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	mContext.startActivity(startMain);

	pm.setComponentEnabledSetting(mockupComponent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
}

The parameters are:
PackageName - the package name of your launcher application.
ClassName - the name of the b4a module that is currently set as the 'home screen activity'.

The code changes the java 'enabled setting' of your home screen activity.
This causes android to forget that the activity was the device's home screen activity.
Finally the code starts your b4a activity.
The user should now be prompted to 'select a launcher app'.

Search the forum for clues on using inline java.
 
Upvote 0
Top