我在Youtube上發佈了一些教程的通知。我認爲一切正常,因爲我看到了通知。問題是我在第二天等待通知。它不起作用。它沒有出現。每日本地通知只出現一次 - Android
這裏是小時等代碼:
button1 = (Button)dialog.findViewById(R.id.btnRegister);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 20);
calendar.set(Calendar.MINUTE, 30);
calendar.set(Calendar.SECOND, 30);
Intent intent = new Intent(getApplicationContext(), Notification_receiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
哦,它開始wiith的onclick按鈕,工作在我的自定義對話框,只與第一個應用程序啓動apear。請幫助我們!
編輯
NotificationReceiver的java:
package com.justfashion;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationBuilderWithBuilderAccessor;
import android.support.v4.app.NotificationCompat;
/**
* Created by otsma on 24.11.2016.
*/
public class Notification_receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent repeating_intent = new Intent(context,ActivitySplashScreen.class);
repeating_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context,100,repeating_intent,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setSmallIcon(android.R.drawable.arrow_up_float)
.setContentTitle("Hey You!")
.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.sound))
.setContentText("Collect today's diamonds!")
.setAutoCancel(true);
notificationManager.notify(100,builder.build());
}
}
加入我的接收器的代碼 –
添加額外的接收器:BootReceiver聽引導和時間表也從那裏發出警報。 – ak0692
我添加了代碼! – ak0692