Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(android) fix not opening activity from notification

Saúl Ibarra Corretgé873267516289
diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java
index a1a49f7433..119a24676c 100644
--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java
+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetOngoingConferenceService.java
@@ -51,30 +51,34 @@ import java.util.Random;
*
* See: https://developer.android.com/guide/components/services
*/
-public class JitsiMeetOngoingConferenceService extends Service
- implements OngoingConferenceTracker.OngoingConferenceListener {
+public class JitsiMeetOngoingConferenceService extends Service implements OngoingConferenceTracker.OngoingConferenceListener {
private static final String TAG = JitsiMeetOngoingConferenceService.class.getSimpleName();
+ private static final String ACTIVITY_DATA_KEY = "activityDataKey";
private static final String EXTRA_DATA_KEY = "extraDataKey";
private static final String EXTRA_DATA_BUNDLE_KEY = "extraDataBundleKey";
private static final String IS_AUDIO_MUTED_KEY = "isAudioMuted";
- private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver();
-
private static final int PERMISSIONS_REQUEST_CODE = (int) (Math.random() * Short.MAX_VALUE);
+ private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver();
+
private boolean isAudioMuted;
+ private Class tapBackActivity;
static final int NOTIFICATION_ID = new Random().nextInt(99999) + 10000;
private static void doLaunch(Context context, HashMap<String, Object> extraData) {
+ Activity activity = (Activity) context;
- OngoingNotification.createNotificationChannel((Activity) context);
+ OngoingNotification.createNotificationChannel(activity);
Intent intent = new Intent(context, JitsiMeetOngoingConferenceService.class);
Bundle extraDataBundle = new Bundle();
extraDataBundle.putSerializable(EXTRA_DATA_KEY, extraData);
+
intent.putExtra(EXTRA_DATA_BUNDLE_KEY, extraDataBundle);
+ intent.putExtra(ACTIVITY_DATA_KEY, activity.getClass().getCanonicalName());
ComponentName componentName;
@@ -154,7 +158,7 @@ public class JitsiMeetOngoingConferenceService extends Service
public void onCreate() {
super.onCreate();
- Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted, this);
+ Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted, this, tapBackActivity);
if (notification == null) {
stopSelf();
JitsiMeetLogger.w(TAG + " Couldn't start service, notification is null");
@@ -190,13 +194,28 @@ public class JitsiMeetOngoingConferenceService extends Service
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
+ final String actionName = intent.getAction();
+ final Action action = Action.fromName(actionName);
- Boolean isAudioMuted = tryParseIsAudioMuted(intent);
+ if (action != Action.HANGUP) {
+ Boolean isAudioMuted = tryParseIsAudioMuted(intent);
- if (isAudioMuted != null) {
- this.isAudioMuted = Boolean.parseBoolean(intent.getStringExtra("muted"));
+ if (isAudioMuted != null) {
+ this.isAudioMuted = Boolean.parseBoolean(intent.getStringExtra("muted"));
+ }
+
+ if (tapBackActivity == null) {
+ String targetActivityName = intent.getExtras().getString(ACTIVITY_DATA_KEY);
+ Class<? extends Activity> targetActivity = null;
+ try {
+ targetActivity = Class.forName(targetActivityName).asSubclass(Activity.class);
+ tapBackActivity = targetActivity;
+ } catch (ClassNotFoundException e) {
+ JitsiMeetLogger.w(TAG + " Could not find target Activity: " + targetActivityName);
+ }
+ }
- Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted, this);
+ Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted, this, tapBackActivity);
if (notification == null) {
stopSelf();
JitsiMeetLogger.w(TAG + " Couldn't start service, notification is null");
@@ -206,9 +225,6 @@ public class JitsiMeetOngoingConferenceService extends Service
}
}
- final String actionName = intent.getAction();
- final Action action = Action.fromName(actionName);
-
// When starting the service, there is no action passed in the intent
if (action != null) {
switch (action) {
@@ -281,8 +297,9 @@ public class JitsiMeetOngoingConferenceService extends Service
@Override
public void onReceive(Context context, Intent intent) {
+ Class tapBackActivity = JitsiMeetOngoingConferenceService.this.tapBackActivity;
isAudioMuted = Boolean.parseBoolean(intent.getStringExtra("muted"));
- Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted, context);
+ Notification notification = OngoingNotification.buildOngoingConferenceNotification(isAudioMuted, context, tapBackActivity);
if (notification == null) {
stopSelf();
JitsiMeetLogger.w(TAG + " Couldn't update service, notification is null");
diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.java
index 82a38a391a..145e64bc5f 100644
--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.java
+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingNotification.java
@@ -73,14 +73,13 @@ class OngoingNotification {
notificationManager.createNotificationChannel(channel);
}
- static Notification buildOngoingConferenceNotification(Boolean isMuted, Context context) {
-
+ static Notification buildOngoingConferenceNotification(Boolean isMuted, Context context, Class tapBackActivity) {
if (context == null) {
JitsiMeetLogger.w(TAG + " Cannot create notification: no current context");
return null;
}
- Intent notificationIntent = new Intent(context, context.getClass());
+ Intent notificationIntent = new Intent(context, tapBackActivity == null ? context.getClass() : tapBackActivity);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, ONGOING_CONFERENCE_CHANNEL_ID);