How to launch activity by means of a notification, when the device is blocked (Off the screen)?

1

I have an application which I need to launch an activity of type called (timbre), the problem is when the device is blocked the activity is not launched, in any other situation if it is launched ... My code to perform that function is this:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData()!=null) {
        //Log.d("WILSON", remoteMessage.getNotification().getBody());

        Map<String,String> data=new HashMap<>();
        String customer=data.get("customer");
        String lat=data.get("lat");
        String lng=data.get("lng");

        Intent intent = new Intent(getBaseContext(), CustommerCall.class);
        intent.putExtra("lat", lat);
        intent.putExtra("lng", lng);

        startActivity(intent);
    }
}

But as I said before, it works for me in any situation, except when the device is blocked .... Any help?

    
asked by Wilson Cajisaca 04.07.2018 в 06:18
source

1 answer

0

You can not show an activity from the screen of block, what I recommend is that you show a notification and when pressed open the screen you want to show

Intent intent = new Intent(getBaseContext(), CustommerCall.class);
intent.putExtra("lat", lat);
intent.putExtra("lng", lng);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
        .setContentIntent(pendingIntent);
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle("Mi aplicacion")
        .setContentText("La alarma se ha activado, por favor presiona aqui para ver la informacion");

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());

Now that if what you want is to create a new call screen, what you want to do is very different, I recommend you see how to create an application that manages and creates calls

    
answered by 04.07.2018 в 19:16