setLatestEventInfo() can not resolve in Android Studio
Solution 1
As see here setLatestEventInfo :
setLatestEventInfo method is removed from Notification class
To create Notification
use Notification.Builder class as:
Notification.Builder builder = new Notification.Builder(MyRemiderService.this);
.....
builder.setSmallIcon(R.drawable. notification_template_icon_bg)
.setContentTitle("ContentTitle")
.....
.setContentIntent(pendingNotificationIntent);
Notification notification = builder.getNotification();
notificationManager.notify(R.drawable.notification_template_icon_bg, notification);
Solution 2
Notification.Builder builder = new Notification.Builder(MainActivity.this);
Intent notificationIntent = new Intent(this,MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);
builder.setSmallIcon(R.drawable. notification_template_icon_bg)
.setContentTitle("Music player")
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = builder.getNotification();
notificationManager.notify(R.drawable.notification_template_icon_bg, notification);
Related videos on Youtube
Jaimin Modi
Peace lover. You-tuber. '8th Relaxation' Subscribe to our channel : https://www.youtube.com/channel/UCfuS0Q81Z2yWnUUXLK4ZNbw?sub_confirmation=1 The motive behind creating this channel is to help people find peace and calm in their daily life or routine. All of the music here will be really helpful to you. Here, you will find all the peaceful music for meditation, relaxation, study, to remove stress, spiritual quotes of God, Krishna etc. We are uploading videos with category containing Soothing relaxation, Meditation, Soft music, Nature sounds, Peaceful music etc. We upload new music videos regularly. http://share.fblinker.com/cne8l The person who is reading this, wishing you all the success in your life. Don't forget to Subscribe the channel. Thanks.
Updated on July 13, 2022Comments
-
Jaimin Modi almost 2 years
I am working in Android Studio and trying to generate notification on Specific date and time. All are going right but, In my Service class setLatestEventInfo() method can not be resolved. I have done same demo in eclipse and there is no any issue with eclipse. I don't want to generate notification on any Button's click or any manual event generation but on specific date and time as I specified.
Code for Service class is as follows :
public class MyRemiderService extends Service { private NotificationManager mManager; @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); } @Override @Deprecated public void onStart(Intent intent, int startId) { super.onStart(intent, startId); mManager = (NotificationManager) getApplicationContext() .getSystemService(getApplicationContext().NOTIFICATION_SERVICE); Intent intent1 = new Intent(this.getApplicationContext(), HomeActivity.class); Notification notification = new Notification(R.drawable.notification_template_icon_bg, "This is a test message!", System.currentTimeMillis()); intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(), 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this.getApplicationContext(), "AlarmManagerDemo", "This is a test message!", pendingNotificationIntent); mManager.notify(0, notification); } @Override public void onDestroy() { super.onDestroy(); }
Please, let me provide solution about it.. Thanks.
-
pradip bhuva almost 8 yearsplease check this for 23+ SDK version