Open the phone default launcher when clicking a button - java

I want to open the phone default launcher, where all the phone's applications are displayed, whenever i click my button.
I've tried to look up for an answer but i couldn't find one,
Is that even possible?
Maybe by passing a category to an intent?

To open the Menu, (as per original question):
Use Activity.openOptionsMenu() method in the OnClickListener of the button
Edit:
Edited question as per OP's comments to open launcher, please refer solution at
How to redirect User to default launcher in an android app?

Related

How can Take permission using an alert Box at just destroy the application in Android

I just want to show an alert box at just killing the application in android.
It's like a Notepad application, if we simply kill the app (on clicking the close button) then we get an alert box asking for save changes.
I just want to add same thing in my application.I have tried onBackPressed() and its working fine on clicking on Back Button. But I need same thing on closing the application.
There is now way to be sure if the app is being closed but you can place a check if the application is in foreground or not which is a better metric IMHO as this tells you when the user moved away from your application.
To check the ProcessLifeCycleOwner this will help you find state of process. You can check this Github sample or this stackoverflow question in how to use it.

Duplicate Shortcut icon on Android

I followed How can I add my application's shortcut to the homescreen upon app installation? to have shortcut icon of my app on screen. It is working fine. But the issue is when I click on the shortcut icon to launch, it creates one more shortcut icon.
How to avoid that? In case I delete one icon, the app creates it again on opening.
I use a flag in Shared Preferences to keep track of whether I created a shortcut already or not. From what I could find, there's no way to check if the shortcut already exists on the home screen.
I tried with sharedpreference and saved its value first time and checking on next call before calling method to create shortcut. Working fine now.

Settings activity

I am making an new android app and I would like to make a settings activity where the use can see about info and settings.
So on android devices you have buttons for settings or else it is presented on screen, when I click that button I do get a menu with the name settings (which I guess eclipse once made automatically) and I do have a activity_settings (as a launcher activity, I don't know if that has any influence or what it means actually) but how can I link the menu tab and the activity?
I mean that when in the menu is clicked on the settings-tab the activity opens.
Can you help me out?
Thanks in advance,
Ide
Yes, what Samarth is saying is true. Read the developer guide before you post questions here. A simple google search will give you links as well.
Here's a complete explanation on how to implement Menus and how to do it: http://developer.android.com/guide/topics/ui/menus.html
Also a similar question on how to create an option Menu: Android, How to create option Menu

Home button brings back to my app

I am making a car launcher application, which contains shortcuts to other apps, when i'm in another app i'd like to press the home button and go back to my launcher
So basically i need to override the home button outside of my app,the override has to work only when my app is opened in the background so when i close my app the home button will work as usual taking you to your default launcher
Can i implement something like this or i'm asking too much?
There is no way to intercept the home button on Android, unless you make your app the home screen. This is for security reasons, so that malicious apps cannot take over your device by overriding all the buttons that can exit. The home button is the one sure shot way to be able to leave any app.
In short, no it's not possible, and even if it were, it is a serious disruption in what a user expects out of an app's behavior.
If you go the route of making your app act be a replacement home screen you'll have to include in the install instructions for the users to set your app as the default launcher.
Then the home button would take them to your app. In order to get it to switch back to the default launcher when they are not in "car" mode would be a bit tricky but you could prolly achieve it with some sort of fork activity that checks if car mode is enabled if so go to your car mode launcher if not go to the default launcher (it gets trickier if the user already has a different 3rd party launcher) So essentially your app will always be the home screen app no matter if car mode is enabled or not, but if it is not then you manually start the "normal" home screen.

How set any application as default from my application?

I'm write launcher switcher. Android show list of installed launchers when I press HOME button. How hide this list or get Home button press event?
What you want is not possible, for obvious security reasons. A malware author could use this feature to replace XYZ app with their own fake XYZ app to attempt to steal private information, without the user's knowledge.
I have solved this issue. I used the method addPreferredActivity of the PowerManager to set default launcher. This method is deprecated and requires a platform key, but I have not found any other way.

Categories