无法访问android.app.PendingIntent包

时间:2017-01-11 15:26:38

标签: android firebase notifications firebase-realtime-database android-notifications

我试图发出通知,但它一直在告诉我

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

这是完整的方法:

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);


                                }
                            }
                        }
                    }
                }

这是问题

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 个答案:

答案 0 :(得分:2)

您不通过构造函数创建PendingIntent。您可以通过其中一种工厂方法创建getActivity(),例如getService()getBroadcast()Iterator<LinkedHashMap<String, String>> resultKeys = leftRightWords .keySet().iterator(); while (resultKeys.hasNext()) { LinkedHashMap<String, String> tempKey = resultKeys.next(); LinkedHashMap<String, String> tempVal = leftRightWords.get(tempKey); System.out.println("Key:"); for (Map.Entry<String, String> entry : tempKey.entrySet()) { System.out.println(entry.getKey() + " " + entry.getValue()); } System.out.println(); System.out.println("Value:"); for (Map.Entry<String, String> entry : tempVal.entrySet()) { System.out.println(entry.getKey() + " " + entry.getValue()); System.out.println(); } }