我的代码......
Button start = (Button) findViewById(R.id.button10);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Nortification_Reciver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Log.d("timeinmills", String.valueOf(calendar.getTimeInMillis()));
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
});
calender.getmills具有正确的值。
Nortification_Reciver.java
public class Nortification_Reciver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent i = new Intent(context, Add_data.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 100, i, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setContentTitle("Test")
.setContentText("Text test")
.setAutoCancel(true);
notificationManager.notify(100, builder.build());
}
}
清单
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<receiver android:name=".Nortification_Reciver"/>
没有通知显示。这段代码有什么不对。?我该如何解决这个问题。我的服务是否开始。?
答案 0 :(得分:0)
您正在使用AlarmManager.RTC_WAKEUP,因此请添加:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
到你的清单。顺便说一句,错误的类名Nortification:)