Forum Xamarin.Android

How To Make An App To Be The Main Launcher?

Hi:

I'm working on a launcher app, where the user will just be able to use my app, i already managed to hide the system bar and set the application to fullscreen, but i'm not able to set the application to be the Main launcher, i want the application to start after system boots, that's why i want to make it a launcher app.

Does anyone how to make it a launcher app?, please help me.

Here it's the code i used to hide the system bar, actually im working on rooted devices, and this method needs to be root.

try{

//REQUIRES ROOT
Java.Lang.Process proc = Java.Lang.Runtime.GetRuntime().Exec(new String[]{"su","-c","service call activity 42 s16 com.android.systemui"});
proc.Wait();
}catch(Exception) {}

The code below does not requires root, it's a normal code, on some devices it's enough to hide the bar, but on some other devices does nothing, that's why i used the root method exposed up.

//Remove Title Bar
this.RequestWindowFeature(WindowFeatures.NoTitle);

//Set Fullscreen
this.Window.AddFlags(WindowManagerFlags.Fullscreen);

Best Answers

  • JamesMontemagnoJamesMontemagno US Xamurai
    edited January 2014 Accepted Answer

    You would need to add a few Intent Actions and Categories to make your app function as a launcher. I created a simple app ad added these intent filters:

    [Activity (Label = "HomeTest", MainLauncher = true)]

    [IntentFilter(new []{Intent.ActionMain}, Categories=new[]{Intent.CategoryHome, Intent.CategoryDefault} )]

  • JamesMontemagnoJamesMontemagno US Xamurai
    Accepted Answer

    Interesting. I was testing it on a 4.2.2 x86 emulator. Unless it is specific to that one device you are testing... which device is it?

    Here is my test video: http://screencast.com/t/oFtLZH6BG

  • JamesMontemagnoJamesMontemagno US Xamurai
    Accepted Answer

    No problem. They most likely did some custom work on their ROM for it which is why you might have needed other launchers. I am not positive though, out of the box they should just work with the code I posted. What happens to those attributes when you compile is that they generate your AndroidManifest.xml which is why you never need to go in and manually edit that XML.

    Glad you have it working.

Answers

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai
    edited January 2014 Accepted Answer

    You would need to add a few Intent Actions and Categories to make your app function as a launcher. I created a simple app ad added these intent filters:

    [Activity (Label = "HomeTest", MainLauncher = true)]

    [IntentFilter(new []{Intent.ActionMain}, Categories=new[]{Intent.CategoryHome, Intent.CategoryDefault} )]

  • FraelReinosoFraelReinoso USMember ✭✭

    Thanks a lot @JamesMontemagno, i already have nearly the same, "Categories = new String[] ...".

    But it's still not working, i found the code i have on another thread, but does not work for me, Im running Android 4.2.2.

    This is what i have:

    [Activity (Label = "Interfaz", Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true)]

    [IntentFilter (new[]{Intent.ActionMain}, Categories = new string[] { Intent.CategoryHome, Intent.CategoryDefault })]

    public class MainActivity : Activity
    {...}

    I Also tested your solution but does not work, anyway thanks.

  • FraelReinosoFraelReinoso USMember ✭✭

    I have tested this on another device and works, i don't understand why it does not work on this one cause it's the same android, it works on ICS (4.0.4) and JB (4.1.2, 4.2.2) but on other devices.

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai
    Accepted Answer

    Interesting. I was testing it on a 4.2.2 x86 emulator. Unless it is specific to that one device you are testing... which device is it?

    Here is my test video: http://screencast.com/t/oFtLZH6BG

  • FraelReinosoFraelReinoso USMember ✭✭
    edited January 2014

    Thanks again @JamesMontemagno, im actually working with this one: http://www.rikomagic.com/en/product/showpro_id_45_pid_20.html

    As you can see, it's running Android 4.2.2 by default, and it's an stock image.

    I attached an screenshot from my device version, and the code im using.

    For Launcher:

    [Activity (Label = "Interfaz", Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true)]
    [IntentFilter (new[]{Intent.ActionMain}, Categories = new string[] { Intent.CategoryHome, Intent.CategoryDefault })]

    To hide system bar (the working one):

    try{

    //REQUIRES ROOT
    Java.Lang.Process proc = Java.Lang.Runtime.GetRuntime().Exec(new String[]{"su","-c","service call activity 42 s16 com.android.systemui"});
    proc.Wait();
    

    }catch(Exception) {}

    To hide system bar (not working on this device):

    //Remove Title Bar

    this.RequestWindowFeature(WindowFeatures.NoTitle);

    //Set Fullscreen

    this.Window.AddFlags(WindowManagerFlags.Fullscreen);

    //Keep Screen Awake

    this.Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);

  • FraelReinosoFraelReinoso USMember ✭✭

    Anyway, if there it's another way to make it start on system boot, i don't need to set it as the main launcher, because all i need it's to make it start by itself and keep the user on it.

    I already managed to hide the system bar, so user will never press home. I know that using Broadcast it's posible to make it start on system boot, but i can't figure out how to do it.

  • FraelReinosoFraelReinoso USMember ✭✭

    Well @JamesMontemagno, i added the next code into the AndroidManifest.xml but does not work at all:

    intent-filter

    action android:name="android.intent.action.MAIN"/
    category android:name="android.intent.category.LAUNCHER"/
    

    /intent-filter

    Anyway i solved it using the old code you posted, but first i had to install a launcher app from PlayStore, then i was able to choose the launcher i will use.

    Thanks a lot for your help and your video, it will be very useful for the forum, Cheers dude.

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai
    Accepted Answer

    No problem. They most likely did some custom work on their ROM for it which is why you might have needed other launchers. I am not positive though, out of the box they should just work with the code I posted. What happens to those attributes when you compile is that they generate your AndroidManifest.xml which is why you never need to go in and manually edit that XML.

    Glad you have it working.

  • FraelReinosoFraelReinoso USMember ✭✭

    Yes, they made a messy work on this rom, this is the most difficult one i've been working with.

    About the attributes, it's supposed to auto-generate the code on the AndroidManifest, but when i checked it, there was no code related, just the label, icon, application and permissions, but none about intent-filter, launch or something like that.

    Anyway thanks a lot @JamesMontemagno, you're doing a very good work and i apreciate it, cheers.

  • FraelReinosoFraelReinoso USMember ✭✭

    And i even found a way to star it on boot using a broadcast receiver, on Java this was a painful work and didn't work at all, i don't know what i did wrong, but i managed to make it work on a easy way.

  • MobilityRetailMobilityRetail SGUniversity

    I have made the launcher successfully, But how do we exit from the launcher we created through an event? like for example from a click event through a button.? thanks

  • HemantaHemanta INMember ✭✭

    Hi All, I have similar requirement. Could you please help me. I am very new to Xamarin.
    My Requirement is as below.
    1. When Device restarts, Start my Application by default
    2. When user in on my application, Either hide Home key, back key permanently or disable their functionality.
    i.e user cant skip my application. Some where in my application i will give control to user to close my application.
    3. When the user not using my Application i.e user is in home screen, If user presses home/back button, My Application
    should start.
    I tried all different solutions provided above. But its not working as expected.

    For Req. 1, I tried below

    [Activity(Label = "LauncherHMI", MainLauncher = true, Icon = "@drawable/icon", LaunchMode = LaunchMode.SingleTask)]
    [IntentFilter(new[] { Intent.ActionMain }, Categories = new[] { Intent.CategoryHome, Intent.CategoryDefault })]

    Issue : When device restarts, it gives me one pop up to choose default launcher between My Application and default launcher already present in device.

    For Req.2, I am not able to do.

    For Req.3, I am not able to do.

    Any Help is appreciated. Thanks

  • HemantaHemanta INMember ✭✭

    Anybody out there, could you please help... ???

Sign In or Register to comment.