Я пытаюсь создать приложение, которое загружает (периодически) данные с сервера и уведомляет пользователя при загрузке.Отправка уведомления без кнопки Android
Я попытался использовать сообщение Toast, но мне нужно уведомление в строке состояния. Я использовал пример кода от developer.android.com, который уведомляет об этом после нажатия кнопки. Но мне нужно отправить уведомление, не нажимая кнопку.
Наиболее точный вопрос является
как вызвать sendNotification после «.Execute» в функции „запустить“, какие аргументы я должен использовать в sendNotification (Что здесь?)?
Этот h.postDelayed
материал находится в OnCreate
метод.
Вот код:
h.postDelayed(new Runnable() {
public void run() {
new WebServiceHandler()
.execute("http://maciekb94.cba.pl/");
Toast.makeText(MainActivity.this, "Pobrano dane", Toast.LENGTH_SHORT).show();
//sendNotification();
h.postDelayed(this, delay);
}
},delay);
}
public void sendNotification(View view) {
Intent intent = new Intent(this,MainActivity.class);
//Uri.parse("http://developer.android.com/reference/android/app/Notification.html"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
// END_INCLUDE(build_action)
// BEGIN_INCLUDE (build_notification)
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.ic_stat_new_message);
// Set the intent that will fire when the user taps the notification.
builder.setContentIntent(pendingIntent);
// Set the notification to auto-cancel. This means that the notification will disappear
// after the user taps it, rather than remaining until it's explicitly dismissed.
builder.setAutoCancel(true);
builder.setContentTitle("Pobrano dane");
builder.setContentText("Wejdź by je zobaczyć");
NotificationManager notificationManager = (NotificationManager) getSystemService(
NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, builder.build());
//END_INCLUDE(send_notification)
}
один и тот же код, который вы реализовали –
вызов 'метода sendNotification' везде, где вам нужно, чтобы показать уведомление. Пожалуйста, напишите больше кода для лучшей помощи. – Rohit5k2
С какими аргументами я должен называть этот метод? – Maciekb