在三星设备上,ActivityTransitions API 可能不会正常调用 Broadcast Receiver。要解决此问题,您可以尝试使用 IntentFilter 来接收 Transition 事件。
以下是代码示例:
public class MyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //处理您的逻辑 } }
MyBroadcastReceiver receiver = new MyBroadcastReceiver(); IntentFilter filter = new IntentFilter(ActivityTransition.ACTIVITY_TRANSITIONS_RESULT_ACTION); registerReceiver(receiver, filter);
TransitionManager transitionManager = new TransitionManager(); transitionManager.addTransition(new Transition.Builder(...) .addTarget(...) .setActivityTransition(ActivityTransition.TRANSITION_ENTER) .setInterpolator(new LinearInterpolator()) .setDuration(200) .setCallback(ActivityTransition.getTransitionCallback(pendingIntent)) .build());
在指定 PendingIntent 时,只需使用 ActivityTransition.getTransitionCallback() 即可。这通常会解决在三星设备上不会调用 Broadcast Receiver 的问题。