Android: Create activity on home screen with user's permission - android

I have created a widget and it's working properly. If the user wants, he can add my application's widget on the home screen. However, what I want is, for my own code to "put the widget on the homescreen" with user's permission; because the widget is the most important part of the application, without which it'd be useless.
I'd like to implement something like the following:
a. For example, when an application tries to start bluetooth, the system tells the user "Ok dude, this application wants to turn on bluetooth, do you want to allow this?". Similarly, "Application X is trying to create a home screen widget, do you want to allow it?".
or
b. When you try to add a widget manually to homescreen, the system shows a list of available widgets that you can choose from, and then you select the one you want. Is there some way where I can call this "list of widgets activity" from my code, when my application starts up?
Thanks for the suggestions!

Related

How to create a shortcut for widget?

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

Android: How to control the home button

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.

Force application to front

The question I'm about to ask may seem dangerous for the user, so here's the story before the question:
I'm working in a compagny that tries to sell Galaxy Tabs to schools (children under 10). So, I've been asked to develop an application that starts on boot showing a login screen. The child HAS to log in before he's allowed to use the tablet (just like logging in a computer).
My application starts on boot, shows the login screen, all buttons are blocked (the kid must not be able to use the tablet before the application lets him) except the home button.
fortunately, it seems impossible to block the home button.
I've been trying to rebring the application to front when onpause/onstop is called, this kind of hacks.
So my question is : Can I prevent an user to quit my application until I let him do so?
I know this sounds like a virus, I'm not really happy to be looking for this kind of solution either.
You have to build a custom Home screen, and then set it as the default Home application.
EDIT: see more on this previously asked question (at How can I create a custom home-screen replacement application for Android?). You can just make your authorization the default Home application, then when they log in it forwards to the regular Home screen. If they hit the home button your app gets called, can check if they have logged in and if they have will just send them to the regular home screen.

Android: Launch Shortcut picker

I have looked everywhere for something related to this. I want to launch a shortcut, based on the shortcuts installed on a device.
A simple way of putting this is my user selects one of his shortcuts through my application. When the user initiates the shortcut through my app, it will perform the exact same thing as if he/she is on the home screen and selects the shortcut.
I can do this individually with the system shortcuts, but I want to have more flexibility for other shortcuts installed on the device.
So basically, I need to figure out how to bring up the shortcut picker (the same list that appears by long pressing a home screen and selecting shortcuts), get the intent to launch that shortcut and store that within my application data for use later. I don't want to actually initiate the shortcut when the user selects it, I just want to remember it for later.
Any help with this would be greatly appreciated :)
I think you are looking for this: https://developer.android.com/reference/android/content/Intent.html#ACTION_CREATE_SHORTCUT

Launch my Activity when any (or selected) Apps are launched

I'm developing a Learning Application. In it, I have an Activity where the user can select some applications from a list of all the applications installed on his device.
Now, I'd like to launch my Activity whenever the user launches any of the selected applications from the app list. Basically I'd like to override the selected Activity by my activity. Once the user complete's some task, the user should be returned to the previously clicked Application.
How do I "Capture" this 'Launching other applications' part? BroadcastReceivers? Any example would be highly helpful. I'd be very grateful if anyone points me in the right direction with reference links.
This is very similar to a Lock Apps Application. But in a very badly twisted kind of way.
I know I have to use a background service to monitor the user activity.
You don't intercept arbitrary application launches, if that's what you're after. Doing this silently goes against the Android (or any reasonable) security model.
What you can do is offer an alternative Home screen.
However, if you just have a list view of available applications, nothing stops you from defining custom behaviours within that list activity.

Categories

Resources