I have the following code:
PackageManager mPackageManager = getPackageManager();
ComponentName component = new ComponentName("com.myPackage", "com.myPackage.GhostLauncher");
mPackageManager.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
mPackageManager.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
overridePendingTransition(R.anim.slide_out_left, R.anim.slide_in_left);
Basically every time this code is launched, the dialog box that prompts the user to select a default home screen comes up, which is what was desired. Once the user selects that default Home Screen, it is launched. My question isn't too difficult, I'm just not sure how to go about doing this: when I tap the button that corresponds to the above code, the dialog box prompting the user to select a default home screen slides in from the right. However, the once the user makes a selection, the Home Screen itself appears using the default animation. How can I override that second animation to also be a slide from right?
You can try moving
overridePendingTransition(R.anim.slide_out_left, R.anim.slide_in_left);
to GhostLauncher.onCreate(), perhaps it's not too late to override the animations because the Activity has not been created yet.
Related
I ran into the following issue: I have an app I want my user to be able to select it as the launcher app. So far, no issues there.
Clearing said selection programmatically also isnt an issue here. Where my issue occurs is the following:
When I my custom launcher programmatically I want to go back to default launcher app, e.g. the default on a samsung galaxy. clearing the launch settings over clearPackagePrefferedActivities clears all of it but once i press the home button I get the dialog to select a default launcher again.
Is there anyway to revert back programmatically to the default launcher?
The user always needs to confirm a change in the default settings. You can always trigger the "default launcher" dialog by
PackageManager pm = getPackageManager();
ComponentName cm = new ComponentName(this, FakeLauncherActivity.class);
pm.setComponentEnabledSetting(cm, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent homeIntent= new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homeIntent);
pm.setComponentEnabledSetting(cm, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Where FakeLauncherActivity is just another Activity in your app with the intent-filter HOME/MAIN/DEFAULT (without LAUNCHER).
If you want to know the default system launcher you could query the intents answering the LAUNCHER Intent, but if the user has another Launcher installed, you will not know which one is the default system launcher.
Even if this is not a complete solution for your question, I hope it helps you in a useful direction.
Hello Friend I'm working on Launcher Application. for select my launcher as Home app a popup is showing in samsung. by using this code.
private void launchAppChooser() {
PackageManager packageManager = getPackageManager();
// get dummyActivity
ComponentName componentName = new ComponentName(context, DummyActivity.class);
// enable dummyActivity (it starts disabled in the manifest.xml)
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
// create a new (implicit) intent with MAIN action
Intent intent = new Intent(Intent.ACTION_MAIN);
// add HOME category to it
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// launch intent
startActivity(intent);
// disable dummyActivity once again
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
but this code is not working on OPPO and HUAWEI. I'm using following line for showing same popup to select home launcher
startActivity(Intent.createChooser(intent,"Select Launcher App"));
This code is showing popup with launcher Apps but when i clicked on any app its not set as default.
Can i open homescreen Activity from setting in OPPO for choosing default launcher like this(please open image). because CM Launcher app is opening this activity
Clicke here to open image
Now i Want To Open This Activity Programetically. and Need Yours help for doing this.
For checking in oppo devices, you have to check if the current default home app package name contains "oppo.launcher".
After that, use this code using it. You can open the default home apps settings in "oppo devices"
Intent intent = new Intent();
intent.setAction(Settings.ACTION_HOME_SETTINGS);
startActivity(intent);
This is an alternative solution for changing the current home app to your launcher app. This intent redirect user to default launcher app list in oppo devices.
When I start Wifi setting page from android's setting page, there is a back button in the top action bar. But there is not when I start Wifi setting from my own app.
The code I am using is:
Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
startActivity(intent);
I know that the wifi setting activity and my activity are already in the same back stack. Is there any way to show the back button in the action bar?
As far as I'm aware, there's no way to do what you want. However, I think that even if there were, it is unlikely that you would actually want to do it.
The "back" button in the action bar is actually an Up button. Clicking it wouldn't take the user back to your app; it would take the user up one level within the device settings.
https://developer.android.com/design/patterns/navigation.html
Try adding
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
or try
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity( intent);
When I press the log out button and come to start(main) screen and when I press the back button from main screen it comes to 2nd screen. but, i want to close the application on click of back button from main screen and close all the activities before that.
while doing research I found,
Intent intent = new Intent(this, Home.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
but its not satisfying my requirement.
You can use this code that I referred from here How to exit from the application and show the home screen?:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Although Android's design does not favor exiting an application by choice.
Related Links:
How to close Android application?
Android exit application
just add line in your code and this will work fine
startActivity(intent);
I have made a simple punch in / punch out time clock application. I want to add the user the option of making a shortcut on the homescreen that will toggle the state of the app(time out / time in) but I don't want this shortcut to open up the app on the screen at all.
here is my setupShortcut()
private void setupShortcut() {
Intent shortcutIntent = new Intent(this, Toggle.class);
// shortcutIntent.setClassName(this, Toggle.class.getName());
shortcutIntent.putExtra(EXTRA_KEY, "ToggleShortcut");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "ToggleShortcut");
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.app_sample_code);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
setResult(RESULT_OK, intent);
}
Toggle.class is an activity that toggles the state for me. In the manifest I have these settings on it
<activity android:name=".Toggle" android:exported="true" android:theme="#android:style/Theme.Translucent.NoTitleBar">
As it is now I can create a shortcut on the home screen then press it. The first time I press it it starts the Toggle activity and completes it fine, but it also opens up the TimeClock activity on the screen. If I then hit the back button I go back to the home. I can now press this shortcut and it will start the Toggle activity and not change the screen. Before I added: shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); It would open up the TimeClock activity every time. Now it is just the first time. But I want it to never show anything on the screen when the Toggle shortcut is pressed. Does anyone have any idea of how to get rid of that?
The problem with launchers is that they start Activities, whereas what you want is to start a Service so you can modify the app state in the background. It sounds like what you really want to do is make a Widget, not a launcher shortcut. You can configure the widget to have a button that sets off a Service that will toggle things in the background.
You can "more simply" make a hidden activity that will do what you want!
This activity must use transparent themes so it never shows and call finish() at the end of the onCreate() without any particular conditions.