Skip to content

Commit

Permalink
Fixed live notification action wont work
Browse files Browse the repository at this point in the history
  • Loading branch information
choiman1559 committed Jul 13, 2024
1 parent 85d9845 commit 6546185
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void processReception(Map<String, String> map, Context context) {
} else if ((mode.equals("send") || mode.equals("hybrid")) && type.contains("reception")) {
if ((NotiListenerService.getDeviceName()).equals(map.get("send_device_name")) && getUniqueID().equals(map.get("send_device_id"))) {
if (type.equals("reception|normal")) {
startNewRemoteActivity(map);
startNewRemoteActivity(this, map);
} else if (type.equals("reception|sms")) {
startNewRemoteSms(map);
}
Expand Down Expand Up @@ -549,21 +549,22 @@ protected void removePairedDevice(Map<String, String> map) {
pairPrefs.edit().putStringSet("paired_list", list).apply();
}

protected void startNewRemoteActivity(Map<String, String> map) {
public static void startNewRemoteActivity(Context context, Map<String, String> map) {
if (map.containsKey("notification_key") && removeListener != null) {
removeListener.onRequested(map.get("notification_key"));
}

if (!map.containsKey("start_remote_activity") || "true".equals(map.get("start_remote_activity"))) {
new Handler(Looper.getMainLooper()).postDelayed(() -> Toast.makeText(FirebaseMessageService.this, "Remote run by NotiSender\nfrom " + map.get("device_name"), Toast.LENGTH_SHORT).show(), 0);
new Handler(Looper.getMainLooper()).postDelayed(() -> Toast.makeText(context, "Remote run by NotiSender\nfrom " + map.get("device_name"), Toast.LENGTH_SHORT).show(), 0);
String Package = map.get("package");
try {
getPackageManager().getPackageInfo(Package, PackageManager.GET_ACTIVITIES);
Intent intent = getPackageManager().getLaunchIntentForPackage(Package);
startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
if(Package != null) try {
PackageManager pm = context.getPackageManager();
pm.getPackageInfo(Package, PackageManager.GET_ACTIVITIES);
Intent intent = pm.getLaunchIntentForPackage(Package);
context.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
} catch (Exception e) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + Package));
startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
context.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.android.volley.Request;
import com.android.volley.Response;
Expand Down Expand Up @@ -39,7 +38,6 @@ public static void addToRequestQueue(Context context, String serviceType, JSONOb
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
String idToken = task.getResult().getToken();
Log.d("ddd", "ddd3: " + idToken);
postPacket(context, idToken, URI, packetBody, listener, errorListener);
} else {
Objects.requireNonNull(task.getException()).printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import androidx.annotation.Nullable;

import com.noti.main.BuildConfig;
import com.noti.main.service.FirebaseMessageService;
import com.noti.main.service.backend.PacketConst;

import java.util.ArrayList;
Expand All @@ -22,6 +23,7 @@ public class LiveNotiProcess {

public static final String REQUEST_LIVE_NOTIFICATION = "request_live_notification";
public static final String RESPONSE_LIVE_NOTIFICATION = "response_live_notification";
public static final String REQUEST_NOTIFICATION_ACTION = "response_notification_action";

public static onLiveNotificationUploadCompleteListener mOnLiveNotificationDownloadCompleteListener;
public static onLiveNotificationUploadCompleteListener mOnLiveNotificationUploadCompleteListener;
Expand All @@ -46,6 +48,7 @@ public static void onProcessReceive(Map<String, String> map, Context context) {
switch (Objects.requireNonNull(map.get(PacketConst.KEY_ACTION_TYPE))) {
case REQUEST_LIVE_NOTIFICATION -> LiveNotiRequests.postLiveNotificationData(context, map);
case RESPONSE_LIVE_NOTIFICATION -> LiveNotiRequests.getLiveNotificationData(context, map);
case REQUEST_NOTIFICATION_ACTION -> FirebaseMessageService.startNewRemoteActivity(context, map);
default -> {
if(BuildConfig.DEBUG) {
Log.e("LiveNotification", "onProcessReceive failed: Action type is not supported: " + map.get(PacketConst.KEY_ACTION_TYPE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,13 @@ public LiveNotiItemHolder(Context context, LiveNotificationData liveNotification
liveNotiBigIcon.setVisibility(View.GONE);
}

//TODO: wont work without noti listener service disabled
remoteRunButton.setOnClickListener((v) -> NotificationViewActivity.receptionNotification(context, liveNotificationObj.appPackage, Device_name, Device_id, liveNotificationObj.key, true));
remoteRunButton.setOnClickListener((v) -> NotificationViewActivity.receptionNotification(context, liveNotificationObj.appPackage, Device_name, Device_id, liveNotificationObj.key, true, true));
dismissButton.setOnClickListener((v) -> {
liveNotiLayout.removeView(liveNotiItem);
if(lastSelectedItemHolder == this) {
lastSelectedItemHolder = null;
}
NotificationViewActivity.receptionNotification(context, liveNotificationObj.appPackage, Device_name, Device_id, liveNotificationObj.key, false);
NotificationViewActivity.receptionNotification(context, liveNotificationObj.appPackage, Device_name, Device_id, liveNotificationObj.key, false, true);
});

liveNotiActionMenuLayout.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.noti.main.service.BitmapIPCManager;
import com.noti.main.service.NotiListenerService;
import com.noti.main.R;
import com.noti.main.service.backend.PacketConst;
import com.noti.main.service.livenoti.LiveNotiProcess;

import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -81,18 +83,30 @@ public static void receptionNotification(Context context, String DEVICE_NAME, St
receptionNotification(context, null, DEVICE_NAME, DEVICE_ID, KEY, isNeedToStartRemotely);
}


public static void receptionNotification(Context context, @Nullable String Package, String DEVICE_NAME, String DEVICE_ID, String KEY, boolean isNeedToStartRemotely) {
receptionNotification(context, Package, DEVICE_NAME, DEVICE_ID, KEY, isNeedToStartRemotely, false);
}

public static void receptionNotification(Context context, @Nullable String Package, String DEVICE_NAME, String DEVICE_ID, String KEY, boolean isNeedToStartRemotely, boolean isLiveNotiResponse) {
SharedPreferences prefs = context.getSharedPreferences(Application.PREFS_NAME,MODE_PRIVATE);
boolean isDismiss = prefs.getBoolean("RemoteDismiss", false);
if(!(isDismiss || isNeedToStartRemotely)) return;
if(!(isDismiss || isNeedToStartRemotely || isLiveNotiResponse)) return;
JSONObject notificationBody = new JSONObject();

try {
if(Package != null) notificationBody.put("package", Package);
if(isDismiss) notificationBody.put("notification_key", KEY);
if(isDismiss || isLiveNotiResponse) notificationBody.put("notification_key", KEY);

if(isLiveNotiResponse) {
notificationBody.put("type","pair|live_notification");
notificationBody.put(PacketConst.KEY_ACTION_TYPE, LiveNotiProcess.REQUEST_NOTIFICATION_ACTION);
} else {
notificationBody.put("type","reception|normal");
}

notificationBody.put("type","reception|normal");
notificationBody.put("device_name", NotiListenerService.getDeviceName());
notificationBody.put("device_id", NotiListenerService.getUniqueID());
notificationBody.put("send_device_name", DEVICE_NAME);
notificationBody.put("send_device_id", DEVICE_ID);
notificationBody.put("start_remote_activity", isNeedToStartRemotely ? "true" : "false");
Expand Down

0 comments on commit 6546185

Please sign in to comment.