问题描述
我需要向用户显示本地通知,如果该用户在1天内没有登录就使用该应用, 2天,4天,8天和16天。我尝试了所有方法,但没有任何帮助。谢谢 前进
public void setLoginAlertNotification(){
long oneDay = 60000 * 60 * 24 ;
scheduleNotification(oneDay*1,"default","1 Day",1);
scheduleNotification(oneDay*2,"2 Day",2);
scheduleNotification(oneDay*4,"4 Day",4);
scheduleNotification(oneDay*8,"8 Day",8);
scheduleNotification(oneDay*16,"16 Day",16);
}
“安排所有通知”
public void scheduleNotification (long delay,String id,String content,int notifyID) {
Intent notificationIntent = new Intent( this,AlarmReceiver. class );
notificationIntent.putExtra(AlarmReceiver. NOTIFICATION_ID_KEY,id ) ;
notificationIntent.putExtra(AlarmReceiver. NOTIFICATION_CONTENT_KEY,content ) ;
notificationIntent.putExtra(AlarmReceiver. NOTIFICATION_CHANNEL_ID,notifyID ) ;
PendingIntent pendingIntent = PendingIntent. getbroadcast ( getApplicationContext(),notifyID,notificationIntent,PendingIntent. FLAG_UPDATE_CURRENT ) ;
AlarmManager alarmManager = (AlarmManager) getSystemService(Context. ALARM_SERVICE ) ;
alarmManager.setExact(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + delay,pendingIntent);
}
“广播接收器接收警报”
public class AlarmReceiver extends broadcastReceiver {
private notificationmanager notificationmanager;
public static String NOTIFICATION_ID_KEY = "notification-id" ;
public static String NOTIFICATION_CONTENT_KEY = "notification-content" ;
public static String NOTIFICATION_CHANNEL_ID = "notification-chan-id" ;
@Override
public void onReceive(Context context,Intent intent) {
String id = intent.getStringExtra(NOTIFICATION_ID_KEY);
String content = intent.getStringExtra(NOTIFICATION_CONTENT_KEY);
int notifyId = intent.getIntExtra(NOTIFICATION_CHANNEL_ID,0);
showNotification(context,content,id,notifyId);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)