I am developing simple home screen application. So when i press home button i can
choose between native and mine home screen app. The problem is: if i set my app as default
home screen application when i restart phone i can't enter native home screen app
because it has never started so my app stands on top off stack. How can i enter
native home screen app when i restart phone if mine is default home screen app?
I have idea:
On boot, i can check the calling intent - if it contains the Home category, i will call native home screen app. Something like this:
Intent creatingIntent = getIntent();
if (creatingIntent.hasCategory(Intent.CATEGORY_HOME))
{
creatingIntent.setPackage("com.android.launcher");
creatingIntent.setComponent(new ComponentName
("com.android.launcher",
"com.android.launcher2.Launcher"));
startActivity(creatingIntent);
finish();
}
But the problem is i don't know how can i get Component name for native home screen application, can someone help?
The goal of an home app (=launcher) is to replace the native launcher, it's weird to force the cohabitation of 2 launchers. But if you success to do something like that, when you press on the home button it will launch also the Native launcher.
To answer your question, the native launcher depends of the target device. Example : samsung doesn't use the same launcher than google, so components name will be different.
Have you tried to do a broadcast receiver which launch your app at start up ? With that, you don't have to put your apps as default home app, so you conserve the choice when you press on the Home button. However, it's not a solution if a user choose your app as default app.
Maybe you can look here How to use customized screen instead of default start screen in Android?
Related
Android M:
I am trying create/resume a service whenever the home button is pressed. The activity that is displayed when the home button is pressed should not be destroyed/paused. I have tried to make my service filter the android.intent.category.HOME intent but android does not seem to recognize this as a launcher. Is there any workaround to solve this problem?
I am trying create/resume a service whenever the home button is pressed.
Implement a home screen. Convince users to use your home screen. Tie your service into your home screen implementation.
The activity that is displayed when the home button is pressed should not be destroyed/paused
The activity that is displayed will be paused, because the HOME button always brings another activity to the foreground. The only exception is if the home screen is already in the foreground. There is nothing that you can do about this, other than write your own mobile OS.
The activity that is displayed will be destroyed if and when Android decides to terminate the process associated with that activity. You do not get a vote.
I have tried to make my service filter the android.intent.category.HOME intent but android does not seem to recognize this as a launcher.
That is because the HOME button will start an activity, not a service.
So there is no way of implementing your own launcher that does not open the Home screen?
You are welcome to implement your own customized version of Android that offers this. Then, you can put that version of Android in your own custom ROM, then convince people to use that ROM.
I have created an app for visually impaired. When the user clicks on Physical Home button I am getting the launcher dialog box working perfectly fine.
Instead of inbuilt dialog box. I would like to get my activity screen which has the list of launchers so that user can select and open any launcher according the requirement.
For e.g.
If the user has two launcher
Launcher (Default)
MyApp launcher
On myactivity screen it should show up launcher and myApp and user should able select anything required.
Is this possible? if so how? Can somebody direct me to that page as a start?
Thanks!
When the user presses the home button, the system is attempting to fulfil the android.intent.category.HOME intent. The dialog pop up is there when there is no user preference, the system will always have control of this UI.
What you could do is fulfil this intent yourself, and be the default launcher - even if your launcher's action is to provide the means to launch another launcher?
I have created the widget, but this widget does not show directly on the home screen, I want it to be displayed directly on the home screen, immediately after the application is deployed, like a shortcut, and clicking on the shortcut widget will go to the application
Can someone suggest me?
Thanks
I want it to be displayed directly on the home screen, immediately after the application is deployed
You cannot run any code at the time the user installs your application. You must wait for them to launch it, or in the case of a home screen widget you must wait for them to explicitly place it on the home screen.
You have to add an intent line to your manifest that exposes the action you want to do through a shortcut.
see: http://android-developers.blogspot.sg/2009/11/integrating-application-with-intents.html?m=1
We're trying to provide an application to the mentally and physically handicapped daughter of my neighbor that let's her use an Android tablet as a Talker, i.e., she presses a few big buttons and the devices generates speech. The application is basically a WebView and an additional object in Javascript used to perform and control the speech generation, plus some logic to handle the orientation changes. Html files are generated offline for her specific layout of the talking items. We've also added some music playing and picture viewing facilities to make the device more appealing to her.
Problem is that the home button brings her back into the madness of the Android launcher screen, and that on the test device (Archos 70) the home button is not a physical button but rather shown on the touch screen itself, making it too easy to accidentally hit it.
So I'd like to return to the Android launcher only by pressing a sequence home, back, home with no other action in between.
Can I achieve this by making my application itself the launcher? How can I then get back to the original launcher upon the home, back, home sequence? It seems that this goes deep into the innards of Android, huh?
The only clue I found so far is Overriding Home button for a Car Home replacement app, but this is rated -1 and reported to work in the emulator only. Also I doubt if I could completely abandon the original launcher, as otherwise there is no access anymore to e.g. the USB mass device control to allow new HTML files to be downloaded, the application to be killed and restarted, and so forth.
I'm willing to go for a kludge as well. Maybe a background service could be started that would bring the application to the front again as necessary?
The Home button cannot be overriden. You can write an application that responds to the home intent (that's what a launcher does) but that's all.
Can I achieve this by making my application itself the launcher? How can I then get back to the original launcher upon the home, back, home sequence? It seems that this goes deep into the innards of Android, huh?
Yes. Not too deep into the
innards. You can manually start a launcher by specifying the component, note that this may vary from device to device and user to user, if you're just using this privately you could hard code it, but if you release it you must allow the user to specify their real home app.
/* This should come from a preference that let's the user select an activity that can handle the HOME intent */
String packageName = "com.android.launcher";
String packageClass = "com.android.launcher2.Launcher";
Intent home_intent = new Intent(Intent.ACTION_MAIN);
home_intent.addCategory(Intent.CATEGORY_HOME);
home_intent.setComponent(new ComponentName(packageName, packageClass));
home_intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
/* Here you should catch the exception when the launcher has been uninstalled, and let the user save themselves by opening the Market or an app list or something. Users sometimes use root apps to uninstall the system launcher, so your fake launcher is all that is left. Might as well give the poor user a hand. */
startActivity(home_intent);
Detecting home/back/home is a bit awkard because home won't come as a onKeyEvent but instead as a new intent. Simply long-pressing the back button then display a prompt is probably a safe/good approach.
I'm trying to track my applications usage on my device.
Is there a way to know if an app was launched from a home screen shortcut or from the launcher?
In the logcat I see there is an ActivityManager log each time an app starts, but I can't tell if there's any difference between shortcut launch and app drawer launch.
Thanks
I don't think you can tell the difference necessarily. If you created the shortcut, you might be able to tuck an extra or something in the Intent to distinguish the cases, but if the user creates the shortcut on her own, there probably is no difference.
Bear in mind that both shortcuts and "app drawers" are constructs of the same home screen application, and some home screen applications may not have shortcuts or may use something substantially different than an "app drawer".