Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Expected Class or Package Error

I cannot figure out why this error is occurring. I am creating an alert button that sends a notification to the user VIA vibrate.

"new NotificationCompat()" is where my error is.

here is the code:

public class AlertReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {

        createNotification(context, "It Is Time To Stand Up!","20 Minutes Have Passed", "Alert");

    }

    public void   createNotification(Context context, String msg, String msgText, String msgAlert ) {

        PendingIntent notificIntent = PendingIntent.getActivity(context,0,new Intent(context,CustomizeAlertsPage.class),0);

        NotificationCompat.Builder mBuilder = new NotificationCompat().Builder(context)
                .setLargeIcon(R.drawable.ALERT)
                .setContentTitle(msg)
                .setTicker(msgAlert)
                .setContentText(msgText);

        mBuilder.setContentIntent(notificIntent);
        mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE);
        mBuilder.setAutoCancel(true);

        NotificationManager mNotificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        mNotificationManager.notify(1,mBuilder.build());

    }
}
like image 988
bdwiggin Avatar asked Dec 06 '25 14:12

bdwiggin


1 Answers

Change

NotificationCompat.Builder mBuilder = new NotificationCompat().Builder(context)

to

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
like image 51
Shadab Ansari Avatar answered Dec 08 '25 05:12

Shadab Ansari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!