使用pendingent时服务返回空

roejwanj  于 2021-07-05  发布在  Java
关注(0)|答案(0)|浏览(167)

大家好,我有一个问题,有一个通知,为朋友的要求与2个行动按钮,当我按下取消按钮,它的工作,但当我按下接受按钮,额外的返回空值,他们都是相同的代码是某种错误?我的代码以前工作过。现在不会了
这是我的密码:
通知代码:

public void showFriendsNotification() {
    if (getnamefromsystem != null && getimagelinkfromsystem != null) {
        Uri alarmSound = RingtoneManager.getDefaultUri(2);
        NotificationCompat.Builder nm = new NotificationCompat.Builder(getBaseContext());
        nm.setColor(ContextCompat.getColor(getBaseContext(), R.color.colorPrimary));
        nm.setSmallIcon(R.drawable.ic_sunbow_noti_x_view);
        nm.setContentTitle("Friend request");
        nm.setContentText(getnamefromsystem + " wants to be your Friend!");
        nm.setPriority(NotificationCompat.PRIORITY_HIGH);
        nm.setDefaults(RingtoneManager.TYPE_NOTIFICATION);
        nm.setChannelId(CHANNEL_ID);
        if (dodefaultimage == false) {
            nm.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.sunbow_100_cir));
        } else {
            nm.setLargeIcon(bfornoti);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Log.e("whoisit", whoisitx);

            Intent ican = new Intent(getBaseContext(), ServiceNotifications.class);
            Intent iacc = new Intent(getBaseContext(), ServiceNotifications.class);

            iacc.putExtra("what", 4);
            iacc.putExtra("service_call", 4);
            iacc.putExtra("whoxxx", whoisitx);

            ican.putExtra("whoxxx", whoisitx);
            ican.putExtra("service_call", 4);
            ican.putExtra("what", 5);

            PendingIntent pncan = PendingIntent.getService(getBaseContext(), 0, ican, PendingIntent.FLAG_ONE_SHOT);
            PendingIntent pnacc = PendingIntent.getService(getBaseContext(), 0, iacc, PendingIntent.FLAG_ONE_SHOT);
            nm.addAction(0, "Accept", pnacc);
            nm.addAction(0, "Cancel", pncan);
        }
        nm.setVibrate(new long[]{200, 100, 200});
        if (Build.VERSION.SDK_INT >= 24) {
            nm.setGroup(ActionNotiGroup);
        }
        nm.setLights(Color.CYAN,1000,1000);
        mNotificationManagerss = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        mNotificationManagerss.notify(33, nm.build());
        callf = true;
        stopSelf();
    }
}

以下是服务代码:

if (intent == null  || getwhattodo == 0) {
            Log.e("runnotix", "work");
            if (getwhattodo == 0) {
                stopSelf();
            }
        }
        if (intent != null && getwhattodo == 2) {
            createNotificationChannel();
            Check_comments();
            Check_friends_request_notifications(accsaveget);
            new GetRequest().execute();

        } else if (intent != null && getwhattodo == 3) {
            Log.e("service run at","friends");
            createNotificationChannel();
            stopSelf();
        } else if (intent != null && getwhattodo == 4) {
            whatneed = Integer.toString(intent.getIntExtra("what", 7));

            String targetreq = intent.getStringExtra("whoxxx");
            Log.e("deatilas" , "req: " + whatneed + " who: " + targetreq);
            if (targetreq == null) {
                targetreq = "aa00";
            }

            new Friends_Actions().execute(targetreq);
        }

所以当我按下accept按钮时getwhattodo return null和service return null,但是当我按下cancel按钮时,它工作。
有时它会在两次按下按钮时返回“取消”按钮值。我哪里做错了?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题