代码之家  ›  专栏  ›  技术社区  ›  Ram Agrawal

PendingContent()在PendingContent中不是公共的;无法从外部包访问

  •  -2
  • Ram Agrawal  · 技术社区  · 7 年前

    我知道这类问题被问到了,但他们无法解决我的问题,因此我再次要求它为我的问题提供准确的解决方案,我正在使用Android Studio 3.0.1创建简单的通知应用程序,当我运行此应用程序时,它向我显示错误,如下所示:

    错误:(40,25)错误:PendingContent()在PendingContent中不是公共的;无法从外部包访问

    我的mainactivity.java如下

    package com.example.ram.notification;
    
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.content.Intent;
    import android.support.v4.app.NotificationCompat;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    
    
    
    
    public class MainActivity extends AppCompatActivity {
    
        NotificationCompat.Builder notification;
        private static final int uniqueID = 45612;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            notification = new NotificationCompat.Builder(this);
            notification.setAutoCancel(true);
    
        }
    
        public void ClickNotification(View view){
            //build the notification
            notification.setSmallIcon(R.drawable.myimage);
            notification.setTicker("this is the ticker");
            notification.setWhen(System.currentTimeMillis());
            notification.setContentTitle("Here is the title");
            notification.setContentText("I am the body of your notificattion");
    
            Intent intent = new Intent(this, MainActivity.class);
    
            PendingIntent pendingIntent = new PendingIntent().getActivity(this, 0,
                    intent, PendingIntent.FLAG_UPDATE_CURRENT);
            notification.setContentIntent(pendingIntent);
    
            //build notification and issues it
            NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            nm.notify(uniqueID, notification.build());
    
        }
    
    }
    

    请帮帮我,我该怎么办?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Hamza    7 年前

    pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);