PendingIntent()在PendingIntent中不公开;无法从外部包裹访问

时间:2018-06-12 06:59:29

标签: java android android-pendingintent

我知道这类问题但是他们无法解决我的问题,因此我再次要求它解决我的问题,我使用android studio 3.0.1创建简单的通知应用程序,当我运行此应用程序,它显示我的错误如下所示:

错误:(40,25)错误:PendingIntent()在PendingIntent中不公开;无法从外包装

访问

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

答案 0 :(得分:2)

只需删除" new" 40行中的关键字

必须是

B