简体   繁体   English

我的通知未检索待处理意图中的附加内容

[英]My notification is not retrieving the extras in pending intent

i have tried most solution but still i don't get the extras when notification is clicked i tried 1 Why the PendingIntent doesn't send back my custom Extras setup for the Intent?我已经尝试了大多数解决方案,但是当单击通知时我仍然没有得到附加信息 我尝试了1 为什么 PendingIntent 没有发回我的 Intent 自定义附加设置? 2 Intent.getExtras() always returns null 2 Intent.getExtras() 总是返回 null

                String itemID = dataSnapshot.child("itemID").getValue(String.class);
                Intent intent = new Intent(UserHomeActivity.this, MapsActivity.class);
                intent.putExtra("id", itemID);
                intent.setAction(itemID);
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

                int uniqueInt = (int) (System.currentTimeMillis() & 0xfffffff);
                PendingIntent pendingIntent = PendingIntent.getActivity(UserHomeActivity.this, 0,
                        intent, PendingIntent.FLAG_UPDATE_CURRENT);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ){
                    CharSequence name ="001";
                    NotificationChannel notificationChannel = new NotificationChannel(Channel_ID, name,NotificationManager.IMPORTANCE_HIGH );
                    notificationChannel.setDescription("This is description");

                    NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
                    notificationManager.createNotificationChannel(notificationChannel);

                    Notification.Builder builder = new Notification.Builder(getApplicationContext(),Channel_ID);
                    builder.setSmallIcon(R.mipmap.ic_launcher)
                            .setContentText(text)
                            .setContentTitle("New Price Added")
                            .setContentIntent(pendingIntent)
                            .setPriority(Notification.PRIORITY_DEFAULT);
                    NotificationManagerCompat  notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());
                    notificationManagerCompat.notify(001,builder.build());

                }else {
                    Notification.Builder builder = new Notification.Builder(getApplicationContext());
                    builder.setSmallIcon(R.mipmap.ic_launcher)
                            .setContentText(text)
                            .setContentTitle("New Price Added")
                            .setAutoCancel(true)
                            .setContentIntent(pendingIntent)
                            .setPriority(Notification.PRIORITY_MAX);
                    NotificationManagerCompat  notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());
                    notificationManagerCompat.notify(uniqueInt,builder.build());

Here is my Code For retrieving the extras这是我用于检索附加内容的代码

        if(extras != null){
                // extract the extra-data in the Notification
                String msg = extras.getString("id");
                String sss = getIntent().getParcelableExtra("id");
            Toast.makeText(this, sss+" ids  "+msg+ "     "+extras.toString(), Toast.LENGTH_SHORT).show();

        }
        imageButton = findViewById(R.id.call);
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent phoneIntent = new Intent(Intent.ACTION_DIAL);
                phoneIntent.setData(Uri.parse("tel:0818283848"));
                startActivity(phoneIntent);
            }
        });     ```


Did you try debugging the extras?您是否尝试调试附加功能? try putting break points and see what your are receiving in through the intent.尝试设置断点并查看您通过意图收到的内容。 Check if the extra is actually getting passed or not.检查额外的是否真的通过了。

If you are not receiving the extra, then your intent is faulty.如果你没有收到额外的,那么你的意图是错误的。 If you are receiving the extra, then the logic of how you access extras is wrong.如果您收到的是额外的,那么您如何访问额外的逻辑是错误的。

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

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