0
votes

So here is my code that sets a notification that the user is bieng called via the zoom service. However if the user does not click the notification and instead just hits the app icon directly the extras are not captured correctly. I am a little lost on how to extract the extras from this pending intent in on resume.

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); //build the new notification mBuilder.setSmallIcon(R.drawable.ic_launcher); mBuilder.setContentTitle(getString(R.string.incoming_zoom_meeting_title)); mBuilder.setContentText(String.format(getString(R.string.incoming_zoom_meeting_message), pushObject.getZoomCall().get(CIConstants.ZOOM_TITLE))); mBuilder.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.constellation)); //This sets the sound to play

                            Intent resultIntent = new Intent(this, MainActivity.class); //set notification click behavior
                            resultIntent.putExtra(CIConstants.ZOOM_MEETING_ID, pushObject.getZoomCall().getString(CIConstants.ZOOM_MEETING_ID).trim());
                            resultIntent.putExtra(CIConstants.ZOOM_USER_ID,pushObject.getZoomCall().get(CIConstants.ZOOM_TITLE).toString());

                            PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                            mBuilder.setContentIntent(resultPendingIntent);

                            int mNotificationId = 001;
                            NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                            mNotifyMgr.notify(mNotificationId, mBuilder.build());

This is then retrived in the main activity via.

    if (savedInstanceState == null) {
        Bundle extras = getIntent().getExtras();
        mMeetingNumber = extras != null ? extras.get(CIConstants.ZOOM_MEETING_ID).toString() : null;
        mMeetingCallerName = extras != null ? extras.get(CIConstants.ZOOM_USER_ID).toString() : null;
        //if there is a meeting id in the intent
        mZoomCallIncoming = mMeetingNumber != null && !mMeetingNumber.isEmpty();
    }

Any help is really appreciated =D.

1

1 Answers

0
votes

In case anyone stumbles on this the easiest way to do this was to go ahead and just put it into a static variable to be retrieved later in the onResume in case the user does not click the notification it will be populated in onResume anyway.

    Intent i = getIntent();

    String meetingId = i.getStringExtra(CIConstants.ZOOM_MEETING_ID_KEY);
    String userId = i.getStringExtra(CIConstants.ZOOM_USER_ID_KEY);
    if (meetingId != null && !meetingId.isEmpty()) {
        CIConstants.ZOOM_MEETING_ID = meetingId;
        CIConstants.ZOOM_CALL_INCOMING = true;
        i.putExtra(CIConstants.ZOOM_MEETING_ID_KEY, "");
        i.putExtra(CIConstants.ZOOM_USER_ID_KEY, "");
    }
    if (userId != null && !userId.isEmpty())
        CIConstants.ZOOM_USER_ID = userId;

    if (CIConstants.ZOOM_CALL_INCOMING) {
        if(!CIConstants.ZOOM_CALL_NOTIFICATION_SOUND_PLAYING) {
            NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
            builder.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.constellation));
            manager.notify("", CIUtility.NOTIFICATION_ZOOM, builder.build());
        }

        createZoomCallDialogue(CIConstants.ZOOM_MEETING_ID, CIConstants.ZOOM_USER_ID);
        CIConstants.ZOOM_CALL_INCOMING  = false; //reset the zoom uri so that it is not called again when activity is resumed from zoom
        CIConstants.ZOOM_CALL_NOTIFICATION_SOUND_PLAYING = false;
        CIConstants.ZOOM_MEETING_ID = null;
        CIConstants.ZOOM_USER_ID = null;
    }