带有通知的警报-没有错误,但未显示

时间:2018-07-23 06:23:53

标签: java android notifications alarm

我正在尝试在Android Studio中使用通知发出警报,我尝试this link,但出现错误“强制关闭”。 Log Cat中没有错误消息。请帮助我找到这个问题。我完整的代码My Complete Code is here

public class MyAlarm extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("Mine", "Set Daily");

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notifications_white)
            .setContentTitle("My notification")
            .setContentText("Hello World!");

        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(001, mBuilder.build());
    }
}

1 个答案:

答案 0 :(得分:0)

我想您尚未在AndroidManifest.xml中包含广播接收器

<receiver 
    android:name="MyAlarm" >
</receiver>