что я хочу сделать, есть уведомление, чтобы сообщить пользователю о предстоящей задаче, которая была добавлена в список дел EVEN без открытия приложения todo. Кстати, я использовал BroadcastReceiver, потому что я прочитал android, чтобы проверить, есть ли какое-либо сообщение, полученное ими. Я знаю, что чего-то не хватает, потому что у меня есть все в mainactivity.java, поэтому это будет сделано, только открыв приложение.добавить уведомление в список дел в android?
вот мой BroadcastReceiver файл общественного класса Broadcast расширяет BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
try {
Bundle bundle = intent.getExtras();
String message = bundle.getString("alarm_message");
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(
context,
"There was an error somewhere, but we still received an alarm",
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
Toast.makeText(context, "received an alarm", Toast.LENGTH_SHORT).show();
}
}
и вот мой mainactivity.java
общественный класс MainActivity расширяет активность {
public NotificationCompat.Builder builder;
public NotificationManager notificationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// NOTIFICATION
AlarmManager alarmMang = (AlarmManager) getSystemService(ALARM_SERVICE);
// ---get current date and time---
Calendar calender = Calendar.getInstance();
calender.add(Calendar.MINUTE, 5);
Intent noteIntent = new Intent(this, Broadcast.class);
PendingIntent pendI = PendingIntent.getActivity(this, 0, noteIntent, 0);
long fireTime = System.currentTimeMillis();
builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Notifications Example")
.setContentText("This is a test notification");
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// // BUTTON NOT
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
notificationManager.notify(0, builder.build());
}
});
// // AET ALARM
Toast.makeText(this, "lilili", Toast.LENGTH_SHORT).show();
alarmMang.set(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis(),
pendI);
notificationManager.notify(2332323, builder.build());
// finish();
}
Что вы пытаетесь? Что вы прочитали? Что конкретно не касалось документации? Чем конкретнее ваш вопрос, тем более вероятно, что вы получите помощь здесь. – EJK
http://www.vogella.com/articles/AndroidNotifications/article.html –