android.app.PendingIntent cannot be accessed ousid

2019-07-07 19:52发布

I'm trying to make notification, but it keeps telling me that

PendingIntent in android.app.PendingIntent is not public it cannot be accessed outside the package

this is the full method:

final Runnable m_Runnable = new Runnable() {
    public void run()

    {
        FirebaseDatabase.getInstance().getReference("messages").endAt(user.getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                //Toast.makeText(Chat.this,user.getUid(),Toast.LENGTH_SHORT).show();
                if (user != null) {
                    for (DataSnapshot ds : dataSnapshot.getChildren()) {
                        Conversation conversation = ds.getValue(Conversation.class);
                        lastMsgMil = Calendar.getInstance().getTimeInMillis();
                        if (lastMsgDate == null
                                || lastMsgDate.before(conversation.getDate())) {
                            if (lastMsgMil < conversation.getTimeinmillies()
                                    || (conversation.getReceiver().contentEquals(user.getUid())
                                    && conversation.getSender().contentEquals(buddy.getId()))) {
                                lastMsgDate = conversation.getDate();
                                //lastMsgMil = conversation.getTimeinmillies();
                                if (conversation.getReceiver().contentEquals(user.getUid()) && conversation.getSender().contentEquals(buddy.getId())) {
                                    conversation.setStatus(Conversation.STATUS_RECEIVED);
                                    FirebaseDatabase.getInstance().getReference("messages").child(ds.getKey()).child("status").setValue(Conversation.STATUS_RECEIVED);
                                }
                                if ((conversation.getReceiver().contentEquals(user.getUid())
                                        && conversation.getSender().contentEquals(buddy.getId()))
                                        || (conversation.getSender().contentEquals(user.getUid())
                                        && conversation.getReceiver().contentEquals(buddy.getId()))) {
                                    convList.add(conversation);
                                }
                                if ((conversation.getReceiver().contentEquals(user.getUid())
                                        && !conversation.getSender().contentEquals(buddy.getId()))) {
                                    //notList.add(conversation.getMsg());
                                    NotificationManager notMan = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                                    Intent intent = new Intent(Chat.this, Chat.class);
                                    intent.putExtra(Const.EXTRA_DATA, conversation.getSender());
                                    PendingIntent pendingIntent = new android.app.PendingIntent(Chat.this, (int) System.currentTimeMillis(), intent, 0);
                                    NotificationCompat.Builder builder = new NotificationCompat.Builder(Chat.this);
                                    builder.setSmallIcon(R.drawable.ic_launcher)
                                            .setContentTitle(conversation.getSender())
                                            .setContentText(conversation.getMsg())
                                            .build();
                                    //android.app.TaskStackBuilder stackBuilder = new android.app.TaskStackBuilder(Chat.this);


                                }
                            }
                        }
                    }
                }

and here is the problem

NotificationManager notMan = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                                    Intent intent = new Intent(Chat.this, Chat.class);
                                    intent.putExtra(Const.EXTRA_DATA, conversation.getSender());
                                    PendingIntent pendingIntent = new android.app.PendingIntent(Chat.this, (int) System.currentTimeMillis(), intent, 0);
                                    NotificationCompat.Builder builder = new NotificationCompat.Builder(Chat.this);
                                    builder.setSmallIcon(R.drawable.ic_launcher)
                                            .setContentTitle(conversation.getSender())
                                            .setContentText(conversation.getMsg())
                                            .build();

1条回答
Bombasti
2楼-- · 2019-07-07 20:27

You do not create a PendingIntent via a constructor. You create a PendingIntent via one of the factory methods, such as getActivity(), getService(), or getBroadcast().

查看更多
登录 后发表回答