无法在包中访问android.app.PendingIntent [英] android.app.PendingIntent cannot be accessed ouside the package

查看:151
本文介绍了无法在包中访问android.app.PendingIntent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图发出通知,但它不断告诉我

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

这是完整的方法:

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

推荐答案

您不能通过构造函数创建PendingIntent.您可以通过工厂方法之一(例如getActivity()getService()getBroadcast())创建PendingIntent.

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

这篇关于无法在包中访问android.app.PendingIntent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆