Recent searches
No recent searches

Alexandru Mogic
Joined Jul 11, 2024
·
Last activity Jul 12, 2024
Following
0
Followers
0
Total activity
7
Votes
2
Subscriptions
2
ACTIVITY OVERVIEW
BADGES
ARTICLES
POSTS
COMMUNITY COMMENTS
ARTICLE COMMENTS
ACTIVITY OVERVIEW
Latest activity by Alexandru Mogic
Alexandru Mogic commented,
Got it to work by using a hacking workaround. I noticed in the logs that a new Activity for zendesk.messaging.android.internal.conversationscreen.ConversationActivity is created when showMessaging is called, so I catch that Activity on the MainApplication and switch it with the current activity so I can finish it later.
Step-by-Step Solution
Step 1: Modify the Application Class
Create a global variable to track the ConversationActivity and use ActivityLifecycleCallbacks to monitor its lifecycle events.
MyApplication.java
package com.example.app;
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.util.Log;
public class MyApplication extends Application {
private static MyApplication instance;
private Activity currentActivity;
@Override
public void onCreate() {
super.onCreate();
instance = this;
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if (activity.getClass().getName().equals("zendesk.messaging.android.internal.conversationscreen.ConversationActivity")) {
currentActivity = activity;
}
}
@Override
public void onActivityStarted(Activity activity) {
if (activity.getClass().getName().equals("zendesk.messaging.android.internal.conversationscreen.ConversationActivity")) {
currentActivity = activity;
}
}
@Override
public void onActivityResumed(Activity activity) {
if (activity.getClass().getName().equals("zendesk.messaging.android.internal.conversationscreen.ConversationActivity")) {
currentActivity = activity;
}
}
@Override
public void onActivityPaused(Activity activity) {}
@Override
public void onActivityStopped(Activity activity) {}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {}
@Override
public void onActivityDestroyed(Activity activity) {
if (activity == currentActivity) {
currentActivity = null;
}
}
});
}
public static MyApplication getInstance() {
return instance;
}
public Activity getCurrentActivity() {
return currentActivity;
}
}
Step 2: Create a Utility Class to Manage Zendesk Messaging
Create a utility class that interacts with the application class to show and hide the Zendesk messaging.
ZendeskManager.java
package com.example.app;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import zendesk.android.Zendesk;
import zendesk.messaging.android.DefaultMessagingFactory;
import zendesk.messaging.android.Messaging;
import zendesk.messaging.android.MessagingDelegate;
import zendesk.messaging.android.UrlSource;
public class ZendeskManager {
private static final String TAG = "ZendeskManager";
public static void initializeZendesk(Context context, String zendeskKey) {
Zendesk.initialize(
context,
zendeskKey,
zendesk -> {
// Your code
},
error -> Log.e(TAG, "Messaging failed to initialize", error),
new DefaultMessagingFactory());
}
public static void showMessaging(Context context) {
Activity currentActivity = MyApplication.getInstance().getCurrentActivity();
if (currentActivity != null) {
Log.d(TAG, "Showing Zendesk messaging");
currentActivity.runOnUiThread(() -> Zendesk.getInstance().getMessaging().showMessaging(currentActivity));
} else {
Log.e(TAG, "No current activity to show messaging");
}
}
public static void hideMessaging() {
Activity currentActivity = MyApplication.getInstance().getCurrentActivity();
if (currentActivity != null) {
Log.d(TAG, "Finishing ConversationActivity");
currentActivity.runOnUiThread(() -> currentActivity.finish());
} else {
Log.e(TAG, "No ConversationActivity to finish");
}
}
}
Hope it helps!
PS: Zendesk please add support for easily hideMessaging the same way as we do for showMessaging
View comment · Posted Jul 12, 2024 · Alexandru Mogic
0
Followers
0
Votes
0
Comments
Alexandru Mogic commented,
Please support this.
View comment · Posted Jul 11, 2024 · Alexandru Mogic
0
Followers
0
Votes
0
Comments
Alexandru Mogic commented,
Vishakha Damle have you found a solution? Facing the same problem
View comment · Posted Jul 11, 2024 · Alexandru Mogic
0
Followers
0
Votes
0
Comments