微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果在1,2,4,8和16天中未登录使用该应用,则显示本地通知

如何解决如果在1,2,4,8和16天中未登录使用该应用,则显示本地通知

我需要向用户显示本地通知,如果该用户在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 举报,一经查实,本站将立刻删除。