-1

I know that this type of question asked but they are unable to solve my problem, Hence I am asking it again for having exact solution to my problem, I am using android studio 3.0.1 for creating simple notification application, when i run this application it shows me errors as show as follow:

Error:(40, 25) error: PendingIntent() is not public in PendingIntent; cannot be accessed from outside package

and my MainActivity.java as follow

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

    }

}

Please help me what should i do?

Ram Agrawal
  • 99
  • 4
  • 13
  • 2
    "Please help me what should i do??" => [Read the manual](https://developer.android.com/reference/android/app/PendingIntent)! It clearly describes how to create instances. – Seelenvirtuose Jun 12 '18 at 07:04
  • 1
    Possible duplicate of [android.app.PendingIntent cannot be accessed ouside the package](https://stackoverflow.com/questions/41594693/android-app-pendingintent-cannot-be-accessed-ouside-the-package) – Vikasdeep Singh Jun 12 '18 at 07:04
  • So what should i do?? – Ram Agrawal Jun 12 '18 at 07:14
  • "So what should i do??" Again with that question ? It has been answered 2 comments above, but you chose to disregard it, so let me make it clearer: **READ. THE. MANUAL.** – 2Dee Jun 12 '18 at 08:05

1 Answers1

2

Simply delete "new" keyword in 40 row

must be

pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Hamza
  • 2,017
  • 1
  • 19
  • 40
  • Also remove the braces `()`. You are calling a static function so don't need to create an instance first. – RobCo Jun 12 '18 at 07:51