简体   繁体   English

三星设备中通知待定意图的问题

[英]Issues with notification pending intent in Samsung device

When we send Parcelable class in pending intent then Samsung device which have Android version 10 or 11 it receives null in receiver activity当我们在未决意图中发送Parcelable类时,具有 Android 版本 10 或 11 的三星设备在接收器活动中收到null

What is the problem in only Samsung devices?只有三星设备有什么问题?

// sending putextra

Intent intent = new Intent(this, AnswerJavaActivity.class);
        intent.putExtra(Constants.INCOMING_CALL_INVITE, callInvite);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

// receiving code sample
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_answer);
handleIncomingCallIntent(getIntent());
}
 private void handleIncomingCallIntent(Intent intent) {
        if (intent != null && intent.getAction() != null) {
            Log.d(TAG, "handleIncomingCallIntent-");

            String action = intent.getAction();
            activeCallInvite = intent.getParcelableExtra(Constants.INCOMING_CALL_INVITE);}}

Custom Parcelable objects have always been a problem, as often the "extras" need to be decoded by code that is in the Android framework and it doesn't know how to decode your custom objects.自定义Parcelable对象一直是一个问题,因为通常“额外”需要由 Android 框架中的代码解码,并且它不知道如何解码您的自定义对象。 There are 2 possible solutions:有两种可能的解决方案:

Wrap your custom Parcelable with a Bundle .Bundle包裹您的自定义Parcelable Sometimes this works as the Android framework doesn't have to unwrap the Bundle .有时这会起作用,因为 Android 框架不必解开Bundle

Alternatively, you need to serialize (convert) your custom object to a byte array and put that in the Intent .或者,您需要将自定义对象序列化(转换)为byte数组并将其放入Intent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM