Android invoke activity after screen is unlocked - android

I'm looking to write an android app that invokes a screen/activity after some one has entered the default android unlock pattern correctly.
I'm assuming that the best way to do this is run a service in the background that waits for this activity then on detecting this invokes an activity screen displaying the information?
Does that sound like a sensible way of doing things or is there a better way?
Also if anyone can point me at examples of this that would be amazing.
Cheers
Ric

Basically you need to register a BroadcastReceiver for the action ACTION_USER_PRESENT
ACTION_USER_PRESENT is fired after ACTION_SCREEN_ON, usually when the keyguard is gone.
So create a handler and wait for ACTION_USER_PRESENT. When you got it, implement what you want for your activity.

Create a broadcast receiver to recieve boot_complete action then create a service and start it from onRecieve of broadcastReceiver .
A good tutorial here

Related

Android/Xamarin: How to launch dialog with broadcast receiver

I want my app to listen for intends broadcasted by the call application, and when a call intend is broadcasted for a specific number I want to launch a dialog. I read that "A broadcast receiver may not display dialogs, and it is strongly discouraged to start an activity from within a broadcast receiver" https://developer.xamarin.com/guides/android/application_fundamentals/broadcast-receivers/ so I am assuming I should instead make the broadcast receiver launch a service that then launches a dialog. Can anyone confirm this? Also any simplified examples would be highly appreciated
Thanks!
In the example below, the app uses a BroadcastReceiver to detect a phone call number and decide whether it should answer or not:
How to reject incoming call programatically in android?
So using a BroadcastReceiver for that isn't that bad.
If you just want to show information about the phone call, you can display an Notification, as suggested by Jon Douglas in the comments. Displaying Dialogs from BroadcastReceivers isn't allowed (also disencouraged).

Android: How to start activity when phone is sleeping, similar to Viber incomming call activity

I am developing an app and this app needs to give a clear indication to the user when some event happens.
Only thing I could do until now is giving a notification in the notification area. But, I need to give a more visible notification, similar to the behavior when phone is ringing in an incoming call.
As I can understand, the reason why android is only allowing apps to give a notification is to prevent apps from disturbing the user. But, this app I am developing plays a vital role in the job of the user, so I don't think it is inappropriate to give a such strong notification.
I know it should be doable since apps like Viber can start an activity similar to a incoming phone call, even when the device is sleeping.
Does anyone know how to get this done?
Register a broadcast receiver, and add a custom action to it say CustomAction.Instead of showing notification, throw a broadcast and add CustomAction via intent filter.
Now in the onReceive method of broadcast listener, check
if(intent.getAction.equals("CustomAction"))Intent i = new Intent(context, YourActivity);
context.startActivity(i);
Sorry for not a formatted answer, I'm driving, will update it later for more clarification.
Update
Register broadcast receiver in a sticky service. So that service can be started automatically if killed and register broadcast register again.
Don't forget to unregister broadcast receiver in onDestroy() method of service and also in YourActivity when you purpose is resolved.
Just adding a sticky service (which does nothing) fixed the issue. Adding the service prevented the process getting killed when user exits the app and removes it from recent app list.
Because of the service, the app process is running even when a no UI is visible. In this state, if an activity is shown from the GCM service, it gets shown.
You can trigger a broascast as Vinay mentioned. If it still does not work, try using wake-locks. These wake-locks help in waking the device when it is in sleep mode. It will act like force wake and after calling wake-locks, you can perform your actions.
Hope it helped..
Thanks.

How to modify incoming and outgoing call screen view in android

I want modify below screen according to my option.
I don't know how to access this screen.
and i need to modify this screen also
Please help me to do this.
You cannot modify default screen but instead of this you can launch your screen for that you need to use BroadCastReceiver for incoming calls
here is the link for getting phone state in broadcast receiver
http://www.tutorialforandroid.com/2009/01/get-phone-state-when-someone-is-calling_22.html
You have to write a broad cast receiver for incoming calls the Pratiks answer have the tutorial for that.Then simply make a pop up window over the default screen. you can call the pop up class from the broadcast receiver. hope you got it:)

Launch app on incoming call (android)

I have an app on Android that reacts to incoming calls.
Now, since the OS shuts my app down whenever it want,
I need a way to to listen to the incoming calls and launch the app when it happens.
Will a BroadcastReceiver help? (just like launching on device restart)
Any idea?
thanks!
I think you have answered your own question. This is just the sort of thing a broadcast receiver is meant for. If the receiver is registered in your manifest then the application does not have to be running.
It will be automatically started when a matching intent is broadcast. Typically the response will be to update content or activities, make notifications with the Notification manager or launch/manipulate services.
Note that there is a 5 second execution limit in the BroadcastReceiver onReceive handler to ensure you do not try to do any 'heavy lifting' in it. Exceed this and a force close dialog will be displayed.
Yes a BroadcastReceiver would to the job as it will fire even you app is not running.

How can I display a dialog from an Android broadcast receiver?

Ideally, I do not want to start an activity to do this. When the WiFi connection is lost, my app needs to close because this is a fatal error for us. I want to display an error message and have the user press an Ok button and then exit the app. What is the best way to go about this?
Thanks!
AFAIK, only activities can display dialogs. If so, and if your BroadcastReceiver is registered by an activity via registerReceiver(), you're set -- just use that activity. If, however, your BroadcastReceiver is registered in the manifest, I think you will have no choice but to do something else.
For example, you could send an ordered broadcast Intent. Your currently-running activity -- if any -- would have a high-priority BroadcastReceiver for that Intent, then can pop a dialog when it receives the broadcast. If, however, none of your activities are on screen, you could have a manifest-registered low-priority BroadcastReceiver pick up the broadcast, if you wanted to display a Notification or something. Here is a blog post that covers a bit more about this pattern.

Categories

Resources