My receiver is not showing notification - why? [duplicate]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This question already has an answer here:
Notification Not showing
7 answers
//I had given intent in oncreate
Intent alarmIntent = new Intent(getContext(), ServiceReceiver.class);
pendingIntent = PendingIntent.getBroadcast(getContext(),
0, alarmIntent, 0);
// here i am setting alarm
public void setALARM(String time, String strDate){
AlarmManager manager = (AlarmManager) getContext()
.getSystemService(Context.ALARM_SERVICE);
String strHour=formateDateFromstring("HH:mm","HH",time);
String strMin=formateDateFromstring("HH:mm","mm",time);
String strdate=formateDateFromstring("yyyy-MM-dd","dd",strDate);
String strMonth=formateDateFromstring("yyyy-MM-dd","MM",strDate);
String strYear=formateDateFromstring("yyyy-MM-dd","yyyy",strDate);
int hour=Integer.parseInt(strHour);
int min=Integer.parseInt(strMin);
int date=Integer.parseInt(strdate);
int month=Integer.parseInt(strMonth)-1;
int year=Integer.parseInt(strYear);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH,date); //1-31
cal.set(Calendar.MONTH,month); //first month is 0!!! January is zero!!!
cal.set(Calendar.YEAR,year);//year...
cal.set(Calendar.HOUR_OF_DAY,hour); //HOUR
cal.set(Calendar.MINUTE,min);//MIN
cal.set(Calendar.SECOND,0);
manager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);
}
//Here is my receiver class
public class ServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.logob_icon_prestigesalon)
.setContentTitle("ABC")
.setContentText("time to go")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
}
}
//I mentioned receiver class in manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name=".ServiceReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<!-- Will not be called unless the application explicitly enables it -->
<receiver android:name=".DeviceBootReceiver"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
I want to set an alarm for the exact time.I checked the code in debug mode whether the debug is coming inside the onReceive if the given time comes.The debug is coming whe the given time is reached.The issue is notification is not visible.
java android
marked as duplicate by Rohit5k2, Mike M.
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 13:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Notification Not showing
7 answers
//I had given intent in oncreate
Intent alarmIntent = new Intent(getContext(), ServiceReceiver.class);
pendingIntent = PendingIntent.getBroadcast(getContext(),
0, alarmIntent, 0);
// here i am setting alarm
public void setALARM(String time, String strDate){
AlarmManager manager = (AlarmManager) getContext()
.getSystemService(Context.ALARM_SERVICE);
String strHour=formateDateFromstring("HH:mm","HH",time);
String strMin=formateDateFromstring("HH:mm","mm",time);
String strdate=formateDateFromstring("yyyy-MM-dd","dd",strDate);
String strMonth=formateDateFromstring("yyyy-MM-dd","MM",strDate);
String strYear=formateDateFromstring("yyyy-MM-dd","yyyy",strDate);
int hour=Integer.parseInt(strHour);
int min=Integer.parseInt(strMin);
int date=Integer.parseInt(strdate);
int month=Integer.parseInt(strMonth)-1;
int year=Integer.parseInt(strYear);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH,date); //1-31
cal.set(Calendar.MONTH,month); //first month is 0!!! January is zero!!!
cal.set(Calendar.YEAR,year);//year...
cal.set(Calendar.HOUR_OF_DAY,hour); //HOUR
cal.set(Calendar.MINUTE,min);//MIN
cal.set(Calendar.SECOND,0);
manager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);
}
//Here is my receiver class
public class ServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.logob_icon_prestigesalon)
.setContentTitle("ABC")
.setContentText("time to go")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
}
}
//I mentioned receiver class in manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name=".ServiceReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<!-- Will not be called unless the application explicitly enables it -->
<receiver android:name=".DeviceBootReceiver"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
I want to set an alarm for the exact time.I checked the code in debug mode whether the debug is coming inside the onReceive if the given time comes.The debug is coming whe the given time is reached.The issue is notification is not visible.
java android
marked as duplicate by Rohit5k2, Mike M.
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 13:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Notification Not showing
7 answers
//I had given intent in oncreate
Intent alarmIntent = new Intent(getContext(), ServiceReceiver.class);
pendingIntent = PendingIntent.getBroadcast(getContext(),
0, alarmIntent, 0);
// here i am setting alarm
public void setALARM(String time, String strDate){
AlarmManager manager = (AlarmManager) getContext()
.getSystemService(Context.ALARM_SERVICE);
String strHour=formateDateFromstring("HH:mm","HH",time);
String strMin=formateDateFromstring("HH:mm","mm",time);
String strdate=formateDateFromstring("yyyy-MM-dd","dd",strDate);
String strMonth=formateDateFromstring("yyyy-MM-dd","MM",strDate);
String strYear=formateDateFromstring("yyyy-MM-dd","yyyy",strDate);
int hour=Integer.parseInt(strHour);
int min=Integer.parseInt(strMin);
int date=Integer.parseInt(strdate);
int month=Integer.parseInt(strMonth)-1;
int year=Integer.parseInt(strYear);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH,date); //1-31
cal.set(Calendar.MONTH,month); //first month is 0!!! January is zero!!!
cal.set(Calendar.YEAR,year);//year...
cal.set(Calendar.HOUR_OF_DAY,hour); //HOUR
cal.set(Calendar.MINUTE,min);//MIN
cal.set(Calendar.SECOND,0);
manager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);
}
//Here is my receiver class
public class ServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.logob_icon_prestigesalon)
.setContentTitle("ABC")
.setContentText("time to go")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
}
}
//I mentioned receiver class in manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name=".ServiceReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<!-- Will not be called unless the application explicitly enables it -->
<receiver android:name=".DeviceBootReceiver"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
I want to set an alarm for the exact time.I checked the code in debug mode whether the debug is coming inside the onReceive if the given time comes.The debug is coming whe the given time is reached.The issue is notification is not visible.
java android
This question already has an answer here:
Notification Not showing
7 answers
//I had given intent in oncreate
Intent alarmIntent = new Intent(getContext(), ServiceReceiver.class);
pendingIntent = PendingIntent.getBroadcast(getContext(),
0, alarmIntent, 0);
// here i am setting alarm
public void setALARM(String time, String strDate){
AlarmManager manager = (AlarmManager) getContext()
.getSystemService(Context.ALARM_SERVICE);
String strHour=formateDateFromstring("HH:mm","HH",time);
String strMin=formateDateFromstring("HH:mm","mm",time);
String strdate=formateDateFromstring("yyyy-MM-dd","dd",strDate);
String strMonth=formateDateFromstring("yyyy-MM-dd","MM",strDate);
String strYear=formateDateFromstring("yyyy-MM-dd","yyyy",strDate);
int hour=Integer.parseInt(strHour);
int min=Integer.parseInt(strMin);
int date=Integer.parseInt(strdate);
int month=Integer.parseInt(strMonth)-1;
int year=Integer.parseInt(strYear);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH,date); //1-31
cal.set(Calendar.MONTH,month); //first month is 0!!! January is zero!!!
cal.set(Calendar.YEAR,year);//year...
cal.set(Calendar.HOUR_OF_DAY,hour); //HOUR
cal.set(Calendar.MINUTE,min);//MIN
cal.set(Calendar.SECOND,0);
manager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);
}
//Here is my receiver class
public class ServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.logob_icon_prestigesalon)
.setContentTitle("ABC")
.setContentText("time to go")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
}
}
//I mentioned receiver class in manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name=".ServiceReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<!-- Will not be called unless the application explicitly enables it -->
<receiver android:name=".DeviceBootReceiver"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
I want to set an alarm for the exact time.I checked the code in debug mode whether the debug is coming inside the onReceive if the given time comes.The debug is coming whe the given time is reached.The issue is notification is not visible.
This question already has an answer here:
Notification Not showing
7 answers
java android
java android
edited Nov 16 '18 at 12:39
Fantômas
32.8k156491
32.8k156491
asked Nov 16 '18 at 12:00
Deepa DineshDeepa Dinesh
418
418
marked as duplicate by Rohit5k2, Mike M.
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 13:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Rohit5k2, Mike M.
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 13:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Not sure if it is your specific problem, but NotificationCompat.Builder(Context context)
is deprecated in API level 26.1.0. You should use NotificationCompat.Builder(Context, String)
instead. All posted Notifications must specify a NotificationChannel Id for 26+ devices as you can check in Notification
and Notification.Builder
documentation
add a comment |
Try something like this,Have not tested.
String channelID = "Notification_Channel_ID";
String channelDesr = "Notification_channel_description";
buildNotificationChannel(channelID,channelDesr);
public void buildNotificationChannel(String channelID, String description) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager.getNotificationChannel(channelID) == null) {
NotificationChannel channel = new NotificationChannel(channelID, description,
NotificationManager.IMPORTANCE_LOW);
channel.setDescription(description);
manager.createNotificationChannel(channel);
}
}
}
NotificationCompat.Builder builder = new
NotificationCompat.Builder(context,channelID)
.setSmallIcon(R.drawable.logob_icon_prestigesalon)
.setContentTitle("ABC")
.setContentText("time to go")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Not sure if it is your specific problem, but NotificationCompat.Builder(Context context)
is deprecated in API level 26.1.0. You should use NotificationCompat.Builder(Context, String)
instead. All posted Notifications must specify a NotificationChannel Id for 26+ devices as you can check in Notification
and Notification.Builder
documentation
add a comment |
Not sure if it is your specific problem, but NotificationCompat.Builder(Context context)
is deprecated in API level 26.1.0. You should use NotificationCompat.Builder(Context, String)
instead. All posted Notifications must specify a NotificationChannel Id for 26+ devices as you can check in Notification
and Notification.Builder
documentation
add a comment |
Not sure if it is your specific problem, but NotificationCompat.Builder(Context context)
is deprecated in API level 26.1.0. You should use NotificationCompat.Builder(Context, String)
instead. All posted Notifications must specify a NotificationChannel Id for 26+ devices as you can check in Notification
and Notification.Builder
documentation
Not sure if it is your specific problem, but NotificationCompat.Builder(Context context)
is deprecated in API level 26.1.0. You should use NotificationCompat.Builder(Context, String)
instead. All posted Notifications must specify a NotificationChannel Id for 26+ devices as you can check in Notification
and Notification.Builder
documentation
answered Nov 16 '18 at 12:38
haroldolivieriharoldolivieri
359315
359315
add a comment |
add a comment |
Try something like this,Have not tested.
String channelID = "Notification_Channel_ID";
String channelDesr = "Notification_channel_description";
buildNotificationChannel(channelID,channelDesr);
public void buildNotificationChannel(String channelID, String description) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager.getNotificationChannel(channelID) == null) {
NotificationChannel channel = new NotificationChannel(channelID, description,
NotificationManager.IMPORTANCE_LOW);
channel.setDescription(description);
manager.createNotificationChannel(channel);
}
}
}
NotificationCompat.Builder builder = new
NotificationCompat.Builder(context,channelID)
.setSmallIcon(R.drawable.logob_icon_prestigesalon)
.setContentTitle("ABC")
.setContentText("time to go")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
add a comment |
Try something like this,Have not tested.
String channelID = "Notification_Channel_ID";
String channelDesr = "Notification_channel_description";
buildNotificationChannel(channelID,channelDesr);
public void buildNotificationChannel(String channelID, String description) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager.getNotificationChannel(channelID) == null) {
NotificationChannel channel = new NotificationChannel(channelID, description,
NotificationManager.IMPORTANCE_LOW);
channel.setDescription(description);
manager.createNotificationChannel(channel);
}
}
}
NotificationCompat.Builder builder = new
NotificationCompat.Builder(context,channelID)
.setSmallIcon(R.drawable.logob_icon_prestigesalon)
.setContentTitle("ABC")
.setContentText("time to go")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
add a comment |
Try something like this,Have not tested.
String channelID = "Notification_Channel_ID";
String channelDesr = "Notification_channel_description";
buildNotificationChannel(channelID,channelDesr);
public void buildNotificationChannel(String channelID, String description) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager.getNotificationChannel(channelID) == null) {
NotificationChannel channel = new NotificationChannel(channelID, description,
NotificationManager.IMPORTANCE_LOW);
channel.setDescription(description);
manager.createNotificationChannel(channel);
}
}
}
NotificationCompat.Builder builder = new
NotificationCompat.Builder(context,channelID)
.setSmallIcon(R.drawable.logob_icon_prestigesalon)
.setContentTitle("ABC")
.setContentText("time to go")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
Try something like this,Have not tested.
String channelID = "Notification_Channel_ID";
String channelDesr = "Notification_channel_description";
buildNotificationChannel(channelID,channelDesr);
public void buildNotificationChannel(String channelID, String description) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager.getNotificationChannel(channelID) == null) {
NotificationChannel channel = new NotificationChannel(channelID, description,
NotificationManager.IMPORTANCE_LOW);
channel.setDescription(description);
manager.createNotificationChannel(channel);
}
}
}
NotificationCompat.Builder builder = new
NotificationCompat.Builder(context,channelID)
.setSmallIcon(R.drawable.logob_icon_prestigesalon)
.setContentTitle("ABC")
.setContentText("time to go")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
answered Nov 16 '18 at 13:27
Ramesh YankatiRamesh Yankati
70659
70659
add a comment |
add a comment |