[英]Status bar Notification not showing up
I have simple notification setup that should show notification on the status bar when the time arrives(Basically remainder). 我有一个简单的通知设置,应该在时间到时在状态栏上显示通知(基本上是剩余时间)。 I set the time like this:
我这样设定时间:
Calendar cal = Calendar.getInstance();
cal.set(2016, 0, 30, 10, 56, 00);
alarmReceiver.setCredentials(NAME,PODCAST);
setAlarm(cal);
The setAlarm
method is given here: setAlarm
方法在此处给出:
private void setAlarm(Calendar target){
Toast.makeText(c, "Reminder set", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), req1, intent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, target.getTimeInMillis(), pendingIntent);
}
This calls AlarmReciever
class which is: 这将调用
AlarmReciever
类,该类是:
public class AlarmReceiver extends BroadcastReceiver {
static int notifyId=1;
String name="";
String disc="";
NotificationCompat.Builder notification;
PendingIntent pIntent;
NotificationManager manager;
Intent resultIntent;
TaskStackBuilder stackBuilder;
public void setCredentials(String n,String d){
name=n;
disc=d;
}
@Override
public void onReceive(Context context,Intent intent) {
//Toast.makeText(context,"Alarm has been set",Toast.LENGTH_SHORT).show();
Log.d("Midhun","onReceiver receiver...");
notification = new NotificationCompat.Builder(context);
//set title for NOTIFICATION
notification.setContentTitle(name);
//message in notification
notification.setContentText(disc);
//Alert shown when notification recieved
notification.setTicker("INVENTO 16");
notification.setSmallIcon(R.drawable.ic_notify);
stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
resultIntent = new Intent(context,MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
pIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pIntent);
manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(10,notification.build());
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(context, notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
}
}
The problem is that the Notification is not showing up. 问题在于通知未显示。
I have tried following: 我尝试了以下方法:
1.I printed a statement from AlarmReceiver
class just to see if that method is called.And the message is displayed in the console at the correct time(The time that i set in the line: cal.set(2016, 0, 30, 08, 56, 00);
) ie. 1.我从
AlarmReceiver
类中打印了一条语句,看是否调用了该方法。消息在正确的时间显示在控制台中(我在该行中设置的时间: cal.set(2016, 0, 30, 08, 56, 00);
)即。 @ 8:56 on 30 jan 2015. @ 2015年1月30日8:56。
2.Also the Toast that is displayed when setAlarm
is called. 2.也调用
setAlarm
时显示的Toast。
So basically the problem is My AlarmReciever class.But i'm unable to figure out what it is. 所以基本上问题是我的AlarmReciever类。但是我无法弄清楚它是什么。
好吧,当我删除语句stackBuilder.addParentStack(MainActivity.class);
时,它开始为我工作stackBuilder.addParentStack(MainActivity.class);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.