Android广播接收器无法启动

Android广播接收器无法启动,android,notifications,alarmmanager,broadcast,receiver,Android,Notifications,Alarmmanager,Broadcast,Receiver,我正在尝试在给定时间启动通知。我输入了BroadcastReceiver,但通知未启动。也许我的错误在舱单上?谢谢你的帮助 public void to_reminder(View v) { Calendar cal=Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 15); cal.set(Calendar.MINUTE, 16); cal.set(Calendar.SECOND,

我正在尝试在给定时间启动通知。我输入了BroadcastReceiver,但通知未启动。也许我的错误在舱单上?谢谢你的帮助

 public void to_reminder(View v)
 { 
     Calendar cal=Calendar.getInstance();
     cal.set(Calendar.HOUR_OF_DAY, 15); 
     cal.set(Calendar.MINUTE, 16);   
     cal.set(Calendar.SECOND, 0);
     cal.set(Calendar.MILLISECOND, 0);

     AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent i = new Intent(this, Notifica.class);
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
am.cancel(pi);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 24*60*60*1000 , pi);
 }



您需要添加
pendingent.getBroadcast
而不是
pendingent.getService
。有关更多详细信息,请参见

试试……我过去也遇到过类似的问题。删除am.cancel(pi);在alarmManagerno中,不要启动。你有一个有效的例子吗?改变maddy说的,她(或他?)是对的
public class Notifica extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent arg1) {

    showNotification(context);
}
private void showNotification(Context context) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, Login.class), 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
            .setSmallIcon(0)
            .setContentTitle("My notification")
            .setContentText("Hello World!");
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    mBuilder.setAutoCancel(true);

    NotificationManager mNotificationManager =
    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, mBuilder.build());

}  
}
 <!-- Broadcast receiver -->
<receiver android:name="reminder.Notifica"></receiver>


</application>