Showing a alert dialog from the any screen of the android phone - android

While pressing the power button we are able to see a alert dialog in any android device from any activity. Just like that i want to show a alert dialogue when my application receives a broadcast intent. How i can implement that function ?

Add this intent to your Activity Manifest tag.
In your Activity's onCreate(), Handle the intent you received:
If it matches your intent, show the dialog.
Else, do nothing.

As the previous person stated, you cannot have this functionality, since it is in the Android Framework code, unless you edit that code to expose it. An example of the functionality you are looking for (from Android code) resides in the PowerUI class, which extends SystemUI. In SystemUI, there is a Context(mContext) that sub-classes use to show Alerts on any screen. This is what you need. I had to recently do this for an app. I just mirrored what PowerUI did, and created another child of SystemUI. The PowerUI does this to let you know that your battery is low(from any activity/screen), among other things.
It's a bit of a bear, but that is what I believe you are talking about. Doesn't really help you much though, if you are releasing to the public. But, for a personal app...

Related

Add subview to arbitary activity android

I'm going to show notification in any view in my Android application, but I didn't find any way how to do it without getting current activity.
On iOS we can just do
Window.AddSubview(customNotification);
But is there any way to do it in Android?
When you refer to notifications in Android, it means the notifications you can see out side the app (see notifications documentation for an explanation). I assume this is not what you are referring to because you are referring to the iOS Window.
Android also has a Window class. However, an Activity is usually the right UI component you should be looking at when adding a custom View. As opposed to iOS, an Android app almost always needs to work in a certain Context to add UI components and you can't just add one to a static Window.
My suggestion is then to change the logic a bit. I assume you have a running Activity at any point (if otherwise and you are running from a Service, perhaps notifications are the right solution after all). So what you can do is to broadcast your request to show certain data and the active Activity will pick it up and add your custom view to itself in the right spot.
Another option is to start a new dialog Activity using the application context.

Android views that can be popped up wherever from application

I have an app that recieves push messages from Google Cloud Messaging.
So when the app is not visible user recieves Notification. If app is visible user recieves Toast. But want to try more interesting solutions if they are exist.
So the question is what views in Android could be called from any Activity of the app like this happens when we use Toast?
Thanks in advance for your answers!
Ok, there is no legal way to do what I wanted. It's possible to invoke AlertDialog, but it will block the current activity. To not block the activity, we can still use Toasts, even custom, but without possibility to make it stay on the screen.
But the best solution is to do nothing, but leave notifications only, doesnt metter if app is visible or not.

Android: how to know previous app

I have 2 different applications A and B and I want to create a special animation from B to A, that is when A is opened after B was visible. This means that I need to somehow know the previous app after which my app was opened. I can have different scenarios of going from B to A - using Recent Apps (multitasking) button, using Back button, using Home button (application A is a custom home screen). Are there any ideas how to do this? Some functions in ActivityManager might help, but they have comments in documentation saying not to use them for implementing logic and control flow.
Not sure if this will work across different applications, but how about getCallingActivity() or getCallingPackage()?
If that doesn't work, could you pass along some 'extra' data in the bundle when you launch the intent that indicates the launching application?
I managed to figure out how to implement this, its working for me.
I used this answer, but replaced the ActivityManager.getRunningTasks() with ActivityManager.getRecentTasks() supplying RECENT_WITH_EXCLUDED | RECENT_IGNORE_UNAVAILABLE, and took the component name from baseIntent member of the result. The info at index 1 is the one that was running before the current app was opened, irrelevant of the fact how you get back to your app - back button, home button, recents button or opened from another app.
NOTE: This works when your app is started, like in onResume() but doesn't work when your app is closed (when called in onPause()) because the new task is not yet loaded into the activity manager. So if you need to also know to which app are you going then it might be a bit more complex.
NOTE2: Although the documentation tells not to use the API above for any kind of logic and control flow, I saw that the multitasking/recent app's code is doing exactly the same, so in my opinion it should not be as risky as they write it docs.
NOTE3: Don't forget to follow all the steps in the answer I mentioned above, like adding needed permissions, otherwise you will get exceptions. Being part of the system in my case makes it much easier for me.

Android activity popup on lockscreen

Ok, first time asking, I couldn't find a solution anywhere..
I'm trying to create an activity that pops up on the lockscreen, kinda like Handcent does (or even Viber, maybe? Can't remember), but I can't for the life of me find a solution that actually works, be it flags, system alert and such
So far I only managed to achieve a workaround by having a dialog themed app and unlocking the phone before showing it but that's not what I'd like to have in the final product, plus it doesn't unlock all kinds of lockscreen (based on user feedbacks, I've had reports of Handcent successfully displaying a dialog while my app can't unlock it)
Is there any tutorial or code snippet for this?
For Unlocking the Phone programatically this should help.
And as you are already using the Dialog Theme, your application's "pop-up" requirements are completed.

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