android.app.PendingIntent cannot be accessed ouside the package

倾然丶 夕夏残阳落幕 提交于 2019-12-11 00:36:37

问题


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:


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().



来源:https://stackoverflow.com/questions/41594693/android-app-pendingintent-cannot-be-accessed-ouside-the-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!