Search code examples
javaandroidtimeclickcall

How can I reach return back to my app after click on "prominent chip"?


From Android 12 there is new notification style Notification.CallStyle for phone calls. Using this template lets your app shows the time duration of the call in the status bar. User can tap this prominent chip to return to their call.

https://developer.android.com/about/versions/12/features#new-calls

enter image description here

I'm using this style in my app for ongoing call notification:

Notification.CallStyle.forOngoingCall

public Notification createOngoingCallNotification(final String callerName, final boolean isMuted)
{
    final Context context = ContextMng.getInstance().APPLICATION_CONTEXT;
    final Intent fullScreenIntent = new Intent(context, CallActivity.class);
    final PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(context, 0, fullScreenIntent, PendingIntent.FLAG_IMMUTABLE);

    final Intent hangUpIntent = new Intent(context, CallNotificationActionService.class);
    hangUpIntent.setAction(CallNotificationActionService.ACTION_INCOMING_CALL_REJECT);
    final PendingIntent hangUpPendingIntent = PendingIntent.getService(context, getRequestCode(GROUPE_KEY_CALL), hangUpIntent, PendingIntent.FLAG_IMMUTABLE);

    final Intent muteIntent = new Intent(context, CallNotificationActionService.class);
    muteIntent.setAction(isMuted ? CallNotificationActionService.ACTION_ONGOING_CALL_UNMUTE : CallNotificationActionService.ACTION_ONGOING_CALL_MUTE);

    final PendingIntent mutePendingIntent = PendingIntent.getService(context, getRequestCode(GROUPE_KEY_CALL), muteIntent, PendingIntent.FLAG_IMMUTABLE);
    final String muteButtonText = isMuted ? context.getString(R.string.Button_Unmute) : context.getString(R.string.Button_Mute);
    final Notification.Action muteAction = new Notification.Action
            .Builder(Icon.createWithResource(context, isMuted ? R.drawable.ic_notification_action_unmute : R.drawable.ic_notification_action_mute), muteButtonText, mutePendingIntent)
            .build();

    final Person callerPerson = new Person.Builder()
            .setName(callerName != null && !callerName.isEmpty() ? callerName : context.getString(R.string.Contact_Unknown))
            .setImportant(true)
            .build();

    final Notification.CallStyle callStyle = Notification.CallStyle.forOngoingCall(callerPerson, hangUpPendingIntent);
    callStyle.setIsVideo(true);

    final Notification.Builder b = new Notification.Builder(context, CHANNEL_CALL)
            .setCategory(Notification.CATEGORY_CALL)
            .setGroup(GROUPE_KEY_CALL)
            .setFullScreenIntent(fullScreenPendingIntent, true)
            .setSmallIcon(R.drawable.ic_notification_logo)
            .setStyle(callStyle)
            .addAction(muteAction)
            .setOngoing(true)
            .addPerson(callerPerson);

    final String channelId = createChannel(CHANNEL_PROCESS, NotificationManager.IMPORTANCE_MIN, -1, null, AudioAttributes.USAGE_UNKNOWN, false);
    if(channelId != null) b.setChannelId(channelId);

    return b.build();
}

If I understand correctly, return to the application after clicking on "prominent chip" is provided by the system. There is no documentation for what has to be done for that feature.

But this doesn't work for me! After clicking on the time (prominent chip), nothing happens. My application did not become foreground.

My project is big. So I created a new one and copied some necessary parts for the simulation. In a new small test project, this click on "prominent chip" has started working. So I think this code is correct. After that, I was searching for reasons why it wasn't working in my main project.

After some time, I discovered that after removing this permission from the manifest:

<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

This click feature will start work on my project on phone Samsung Galaxy S23 (Android 14), but not on Pixel 4 (Android 13).

This is not a solution for me, as I need this permission.

For other apps on my phone like the default dialer or WhatsApp that feature is working all the time.

What has to be done, or what could be the problem that it doesn't work for me?


Solution

  • Now I figure out this solution. I have to change

    this

    setFullScreenIntent
    

    by

    setContentIntent