Notification notification= new NotificationCompat.Builder(this,"myapp")
این خط رو زیرش قرمز میکنه و وقتی کرسر روش قرار میدم این ارور نشون میده
cannot resolve constructor 'Builder(anonymous android.view.View.OnClickListner,java.lang.String)'
-------------
package com.sevenlearn.notification_tutorial2;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import android.app.Notification;
import android.app.NotificationManager;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private View v;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
v=findViewById(R.id.button);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Notification notification= new NotificationCompat.Builder(this,"myapp")
.setSmallIcon(android.R.drawable.stat_notify_chat)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.setContentTitle("My Notification")
.setContentText("this is my first notification ")
.build();
NotificationManager notificationManager=getSystemService()
}
});
}
}
-----------------------
package com.sevenlearn.notification_tutorial2;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
NotificationManager notificationManager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationChannel notificationChannel= new NotificationChannel("myApp","defaultChannel",NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setDescription("test");
if (notificationManager!=null)
notificationManager.createNotificationChannel(notificationChannel);
}
}