拥有拦截推送通知的Android SDK,并使用通知“跳板”进一步打开终端活动。在深度链接的情况下,使用此SDK的应用程序将打开配置的深度链接处理程序活动。
trampoline
的片段:
public class NotificationTrampolineReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
final PendingResult asyncResult = goAsync();
ExecutorService executor = Executors.newSingleThreadExecutor();
asycTask(executor, new Runnable() {
@Override
public void run() {
String urlStr = getStringExtra(intent, PUSH_URL);
if (urlStr != null) {
var intent2: Intent = Intent(Intent.ACTION_VIEW, Uri.parse(urlStr));
if (intent2 != null) {
intent2.addFlags(FLAG_ACTIVITY_NEW_TASK);
intent2.addFlags(FLAG_ACTIVITY_BROUGHT_TO_FRONT);
context.startActivity(intent2);
logAnalytics(intent, Message.MessageAction.OPEN);
}
}
asyncResult.finish();
}
});
}
void asycTask(ExecutorService executor, final Runnable task) {
try {
executor.execute(task);
} catch (Throwable ex) {}
}
}
Android 12不再支持使用notification trampolines
。在SDK中,通知跳板用于拦截点击并执行诸如记录分析事件、在点击通知上的Action
按钮时关闭通知抽屉等操作。但是该SDK并不知道应用程序可能配置以处理深链接的活动。
使用虚拟活动来替换trampoline
是可行的,但感觉不太对,即打开一个活动,然后在其中打开另一个活动,然后结束此活动。
当Android 12限制notification tramoline
时,是否提供了类似这里的用例的替代方案?目前还没有找到。
拦截推送通知的点击并首先打开活动的建议新解决方案是什么?