Android: displaying icons on device's desktop - android

I would like to know how does Facebook messenger work. I mean, I guess there is a service running in the background, with a broadcast receiver. What really baffles me is that when I receive a message, a circle with the person's profile picture pops up on my home screen.
https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQ7ik8VPHOc1oRK3Vf-LtoZPtSPtdtGZzgecoFsK49HXYiKdMV4
How exactly can I achieve that? Displaying icons to the desktop. (No, I do not want to set shortcuts).

I have not used the Facebook app, so I might misunderstand what you want to do, but it might be achieavable with a widget?
If you want a more 'dynamic' experience, without needing the user to place the widget, you can use an Intent or a Broadcast to launch a transparent Activity (here is a SO question on transparent activties). This Activity can then display any views you want to show on top on whatever the user currently is viewing (such as the home screen).

Related

What's the best way to launch a view after device is unlocked?

I'm trying to display a view that the user must dismiss each time they unlock their phone (it's intended to be annoying). It should be able to take a small amount of keyboard input, save it, then return to the previously open activity. I tried having a BroadcastReceiver listen for ACTION_USER_PRESENT and launch my own activity, but then I found out we can no longer listen for implicit intents, or have background services launch activities.
I'm not an Android developer (just trying to build something for my phone), but I did some looking, and I see a few options:
Display a full-screen intent. I think something like scheduling a job to raise a notification whenever the phone is locked, so that the notification appears first thing when they unlock the phone.
Use SYSTEM_ALERT_WINDOW and draw my view as an overlay whenever the phone is unlocked. My only concern with this is how apps like Twilight (which I believe draws an overlay to redden the screen) might interact with it. In those cases, I'd like my overlay to appear at the very bottom.
Are either of those options viable or recommended? Any other suggestions or approaches for how I could accomplish this would be greatly appreciated too. I'm just looking for some guidance on what direction I should pursue.

Android: Click/Touch Management

Big Picture:
User is on their device home screen with an overlay from my application in an arbitrary corner. Overlay is small icon with no functionality (can register if it has been touched) other than presence.
Is it possible to know when the user has clicked OUTSIDE the overlay. I can tell when the user touches the overlay itself, but would like to know if the user has touched the screen but not the overlay?
Does not matter what is being touched, just if the screen is being touched on their device.
Also, same scenario, is it possible to know that the user has clicked a button? For instance, the user clicks the contacts application (or camera, or any application), is their a way to read that action? Do not care what application/button is clicked, just that one was clicked.
Just trying to learn what is possible, so please no need to write out code. Maybe just some pointers in the right direction. Thanks for input.
For the first scenario you can try chat heads(like Facebook messanger) by using intentservice.

Adding the button on native dialer

I'm in the process of developing an Android app for which I need to add a button on the native call screen of the android. Is it possible to add a new button to the existing android call screen or should I create a custom screen specific to my app?
Edit: I want to add a button in addition to send the message to the defualt set number.
should I create a custom screen specific to my app?
Creating your own dialer would be a better option.
This is because even though you can draw your view using the android.permission.SYSTEM_ALERT_WINDOW you will still need to:
get the number the user has just entered (not dialed).
different devices may have different dialers so your button may not be positioned in all devices.
you need a mechanism which monitors if the user has opened the dialer. This will drain the battery.
Edit: I want to add a button in addition to send the message to the
defualt set number.
You can also create a Home Screen Widget for the same. Why even open the dialer?

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.

How to getLocationOnScreen from a Shortcut or Widget?

When a user presses a shortcut on the screen and that shortcut starts up an activity, how can I get the location of where the shortcut is on the screen?
I have the same question for a widget. When a user has a widget on the screen and pressing it fires off the setOnClickPendingIntent how can I know the location on the screen where the widget is?
In both scenarios there is no View to run View.getLocationOnScreen.
When a user presses a shortcut on the screen and that shortcut starts up an activity, how can I get the location of where the shortcut is on the screen?
You can't, sorry.
When a user has a widget on the screen and pressing it fires off the setOnClickPendingIntent how can I know the location on the screen where the widget is?
You can't, sorry.
The only way to get any of that would be to write your own home screen, where you are handling the shortcut presses and app widget taps.
EDIT: The way the QuickContactActivity achieves the effect described in the comments is via getSourceBounds(), a method on Intent. This Rect may or may not be available on any given Intent, and therefore any code looking to use it should be able to cleanly react to an Intent that has no such value. I can see where RemoteViews, the basis for app widgets, use it. I am having a bit more difficulty seeing under what other circumstances the Launcher application uses it. Bear in mind that not all home screens may elect to use it. I apologize for my erroneous original answer.

Categories

Resources