Hello my question is a bit difficult let me explain and try to understood
I have a custom Home who is set as default when user press home. Know i need a way to ask wich home use when i press on a setting key, or a way to launch Setting activity for delete home default action.
In fact i wan't a way to go back to home app installed by google instead of mine just in case.
I need this because my custom home is still in dev and don't have all feature yet.
I need to keep my home as a default action when user press home buton but i need to add a home selector in special case.
I have try to use finish() when i need to go back to old home but mine as default is automaticly relaunch because he is the default one.
Any idea?
EDIT
I try to reformul a bit.
I'm making a home apps. I set it as default on my tablet. My home apps don't have all feature yet. And when i will launch something or go to setting i need to relaunch default home app.
So i need a way inside my app to reset default home action or launch a home apps, or ask user to choice wich app he will use has home apps.
Hope this is clear for all.
Probably you should use this one to implement your idea. keep the below lines in your manifest file.
<activity android:name="Home"
android:theme="#style/Theme"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
For more info about the sample project. just go the below path in your Android SDK
\android-sdk\samples\android-8\Home
EDIT :
Hi Please check this to pro grammatically unset the default application.
How do I use PackageManager.addPreferredActivity()?
for more info go through this also to clear the clearPackagePreferredActivities
http://developer.android.com/reference/android/content/pm/PackageManager.html#clearPackagePreferredActivities%28java.lang.String%29
hope this helps you.
Related
I am writing Android application for kiosk mode. I am using this tutorial to create kiosk mode: http://www.andreas-schrade.de/2015/02/16/android-tutorial-how-to-create-a-kiosk-mode-in-android/
However, in the tutorial, the user still can click on home and then the application back after 2 seconds.
So, I did a bit of modification to disable the home button by making my application as a home. I did it by put this in my manifest:
<activity android:name=".MainActivity"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Everything work well. But when the user try to exit (ie. user login as administrator), my application is back again. I suspect because I set it as HOME.
My question is, how to allow my app to Exit. Is it possible to go back to actual home when my app exit? If not, is there a better way to tackle this home problem (ie. disable home button and not actually set it as home)?
You have multiple HOME screens installed (the default one provided by the device manufacturer, and your app). The user must have chosen that your app should be the default HOME screen (this usually happens at boot time). What you now want to do is to remove this "preferred" setting so that the user can choose a different "default" HOME screen (ie: the manufacturer's app). Do that like this:
PackageManager pm = getPackageManager();
pm.clearPackagePreferredActivities ("your.package.name");
and then finish() your MainActivity.
EDIT: Alternative solution
As an alternative solution, when you want to "exit" your app, you just launch the default HOME screen instead. To do this, you need to either know the package and class name of the default HOME screen and hardcode that, or you can scan for that info using PackageManager like this:
PackageManager pm = getPackageManager();
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> infoList = pm.queryIntentActivities(homeIntent, PackageManager.MATCH_DEFAULT_ONLY);
// Scan the list to find the first match that isn't my own app
for (ResolveInfo info : infoList) {
if (!"my.package.name".equals(info.activityInfo.packageName)) {
// This is the first match that isn't my package, so copy the
// package and class names into to the HOME Intent
homeIntent.setClassName(info.activityInfo.packageName,
info.activityInfo.name);
break;
}
}
// Launch the default HOME screen
startActivity(homeIntent);
finish();
In this case, your app is still set as the default HOME screen, so if the user presses the HOME key again, your app will be started. But the user can then "exit" your app to return again to the original HOME screen.
You can use the device owner capabilities introduced in Android 5.0 to fully manage an Android device and use it as a kiosk. Among other things this allows you to prevent the user from exiting the app by tapping the home button.
The simplest way to set up a device owner kiosk is to use the Android Management API and configure a kiosk policy.
This question already has answers here:
App completely restarting when launched by icon press in launcher
(15 answers)
Closed 2 years ago.
As far as I know by default android app resumes when user clicks on its icon.
But for some reason my app (which I want to have the same behavior) restarts.
When I hold the home button and then select my app from "recent" I get it resumed.
I want the same behavior on clicking the app icon.
actually it's the same as https://groups.google.com/forum/?fromgroups=#!topic/android-developers/UjWcsFMe6ik
but they didn't find an answer
upd:
manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk a:minSdkVersion="10" a:targetSdkVersion="11"/>
<uses-permission a:name="android.permission.INTERNET"/>
<uses-permission a:name="android.permission.ACCESS_FINE_LOCATION"/>
<application a:label="#string/app_name"
a:theme="#android:style/Theme.NoTitleBar"
a:name="myapp.AppDelegate">
<activity a:name="myapp.activities.AuthorizationActivity"
a:label="#string/app_name"
a:screenOrientation="portrait"
a:alwaysRetainTaskState="true">
<intent-filter>
<action a:name="android.intent.action.MAIN"/>
<category a:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity a:name="myapp.activities.activity1"
a:screenOrientation="portrait"/>
<activity a:name="myapp.activities.activity2"
a:screenOrientation="portrait"/>
...
<activity a:name="myapp.activities.activityN"
a:screenOrientation="portrait"/>
<service a:name="myapp.location.LocationService"/>
</application>
It's all about IDE.
After closing an app which was started by IDE (eclipse or IDEA - doesn't matter) Android deletes all it's temporary data (don't ask me why)
So the solution is:
1) run app from ide (deploy it on device)
2) press back button to close an app
3) start an app again
...
and now it will resume working after quitting
Check launch mode of your activity. If its singleTask then make it standard and then check it.
Clicking the app icon will bring the task containing the main activity to the front.
To get the desired behavior make sure all your activities belong to the same task, i.e. don't use singleTask or singleInstance on any of the activities.
Well, just like the title suggests, every activity within my application is being added to the app drawer.... Im really hating this new ADT. First it was a problem with the app name appearing as the first activity name, now all the activities are showing up on the application list. If I go to uninstall it only shows 1. Anyone else having this problem and has figured out a work around?
for future cases specifically you can change in the android manifest under :
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
change to:
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
This will remove the activities' icon from the app drawer. As the OP says: sometimes the wizard puts this in the manifest for you.
Ok, figured it out... Everytime you create a new activity through the adt wizard (New -> Android Activity) it creates the code in your manifest for you.... the problem is that it added intent filters to it as well. Just remove those and they dont show up.... stupid adt.
I know when I am using IntelliJ as my IDE for Android programming, there is a box you can check when using the wizard to create a new Activity that says "Mark as start-up Activity".
Be aware of these types of things because that is what caused me to have the same problem you had Shaun.
I wouldn't completely erase the intent filters, simply have only the Activity you want as the "start-up" Activity marked as the "Launcher" in the Manifest file. All other Activities get "Default".
How to disable the home key when the menu or Alarm Dialog pop up?
I know how to disable the home key in the activity. But when the menu or Alarm Dialog pop up, the way is invalid. How to implement this function. Or is there no way to deal with this case?
You can not disable Home Key . for this is the last chance the Android System ESCAPE the application.
I had the same requirement in my project. Here is my solution:
1) You should have a rooted device.
2) Make sure that your activity is main activity, it should have params like these:
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
If you have it, when you tap home button android suggest you other apps except Launcher...
3) Next, since we have rooted device, just find and rename Launcher.apk to LauncerBBB.apk(it can be done programmatically even).
4) That's all. Now only your app is main and it will be shown by Home key tap.
P.S. If you need to have an access to Launcher you can start LauncerBBB activity from secret menu of your application.
I have been working on a replacement for the stock Car Home app for a bit, and I am completely stumped on how to override the Home button so that my app will be brought back to the foreground whenever the phone is docked. This is the way that Car Home works, so there must be a way.
It seems that BroadcastReceivers won't work, because the intent that is broadcast whenever the Home button is pressed will still cause the default homescreen app to launch; I cannot prevent it. I can override the Home button from within my app, but that does me no good since this needs to work when the user is outside my app. Car Home also does not do anything weird like set itself as the default homescreen app while it's running (I checked the logcat to make sure).
What can I try next?
Well, after many months I have finally found the answer to this question. The key is the "android.dock_home" metadata element, found here:
http://developer.android.com/reference/android/content/Intent.html#METADATA_DOCK_HOME
By using this in your AndroidManifest.xml, you can make your dock application become the home application temporarily. To do this, add this line to the AndroidManifest.xml inside the Activity tags for the dock app activity:
<meta-data android:name="android.dock_home" android:value="true" />
If the value is set to true, as long as your phone is docked the Home button will return you to the dock app. After undocking, the Home button will take you back to your normal home app.
Unfortunately, there is no way in the public APIs to override the Home button without the user confirming it.
Your best bet would be to implement a CATEGORY_HOME Intent. This means when a user pressed Home they would be presented with the option to run the standard Home or yours and make yours the default if they wanted.
When your application was launched you could then check if the phone was docked. If the phone is not docked you could then open the standard Home screen and close your app before anything is displayed.
You need to the correct intent filter in your manifest for the app to launch automatically when you dock the phone. Refer to http://developer.android.com/reference/android/content/Intent.html#CATEGORY_CAR_DOCK for the information.
I found a way to tackle HOME key. For your application set the manifest as
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
Now your application is an alternate Launcher application.
Use the adb, and disable the launcher application using package manager
pm disable com.android.launcher2.
Now the Home key press will aways stay in the same screen.