How to show a call activity when the device is locked and turned off

Asked

Viewed 332 times

0

I’m developing a Video and Voice app.

What I need is to show an Activity the call request when one user tries to call another.

I’m already using Firebase Cloud Message to push messages to the device, warning it that it has a call request.

But I am facing some problems trying to wake up the device and show in front of the lock screen the call Activity for the user to accept or reject the call.

What I’m trying to do is similar to what the Whats App does when you get a call.

Foto de uma chamada do WhatsApp sendo recebida

Show this when the device is Unlocked and the app is in foreground is not difficult, my difficulty is exactly in showing it when the device is locked and in Rest mode (black screen).

  • Good morning my dear! Do you know you will face many problems getting away from this? I advise you to take a look at Q-communicate, using the Quickblox. Download it and import a project and study it well. Surely you will learn a lot.

  • You want to open an Activity instead of appearing the notification?

  • @ramaral would be just that, I imagine that the image of Whatsapp, is an Activity and not a simple notification. Because there are many actions that can be taken from that screen and if you answer she has to give a Unlock on the device and open the app to make the call

  • I’ve never used Whatsapp, does it appear without user intervention? Can you put the code your app uses for sharpening?

  • Basically what happens in the Whats app is as follows. If you make a call (call) to another user in the Whats app, this screen is displayed to answer the call (accepting or rejecting it). And this screen of the image I put up is presented exactly like this, even when the device is locked and at rest.

  • Unfortunately I won’t be able to post the code now, I don’t have access to it right now.

Show 1 more comment

2 answers

0

One of the things you need to know is basically Run a Service in the background on Android. Remembering that to create a service, you must create a sub-class of Service that in its implementation, you need to overload some call methods that manipulate key aspects of the life cycle service and provide mechanisms for components to connect to the service as shown also in the diagram below.

A service is in "Started" form when an application component (as an Activity) starts it by calling startService().

Do you know that you will face many problems when it comes to this? Well then, I advise you to take a look at Q-communicate, which is a project Open Source super cool that uses as a basis the Quickblox. Download it and import a project and study it well. You will surely learn a lot.

Take a look at this diagram that in the return path there are several different returns of other methods when it comes to Service Api.

inserir a descrição da imagem aqui

  • Hello @cleidimar-Viana, thanks for the reply. But I already get notifications via Firebase Cloud Message. So my app even with device locked and in sleep mode receives notifications. What I need is from this to implement my doubt posted here. For this I don’t need a Service running all the time for my app.

  • @Erickgallani as I commented in the reply, you can read on Running a Service in the background. This article is a translation of an article made available by Google itself and may help you a lot in the implementation. Good Luck!

0

I think what you are looking for is one of the new features introduced by Lollipop(API21) in the notification system.

Making use of the new property visibility, class Notification, it is possible to indicate to the system when and how it should reveal the presence and content of a notification.

There are 3 types of "visibility":

  • Secretive (Notification.VISIBILITY_SECRET) - Notification is considered sensitive and is not shown in "lock screen". This is the default behavior(default).
  • Privy (Notification.VISIBILITY_PRIVATE) - The notification is considered sensitive only with respect to the content. It is presented in "lock screen" but the content of the message is replaced by "Contents Hidden".
  • Public (Notification.VISIBILITY_PUBLIC) - The notification is considered to be non-sensitive and the notification is fully shown on "lock screen"

The property can be "set" using the Notification.Builder.

Notification notification  = new Notification.Builder(this)
  .setCategory(Notification.CATEGORY_MESSAGE)
  .setContentTitle(title)
  .setContentText(text)
  .setSmallIcon(icon)
  .setAutoCancel(true)
  .setVisibility(Notification.VISIBILITY_PUBLIC).build();
NotificationManager notificationManager = 
                        (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(notification_id, notification );

Note: This property is only available from API21. A appcompat makes it accessible and can be used, but its effect is only felt on a device with Android 5 or more.

  • 1

    thanks for the tips, but what I think is best suited to what I’m trying to do is this here http://stackoverflow.com/questions/3793221/how-to-display-activity-when-the-screen-is-locked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.