android:在特定时间显示通知?

CSa*_*awy 3 time notifications android

我有一个名为的函数show_notification(),当用户点击按钮时我会调用它.关键是,一旦他点击[如下面的函数],我不想显示通知,我想在特定的time= hours:mins
地方显示此通知.小时和分钟是两个整数,具有我想要的时间值[例如小时= 22和分钟= 40 ..意思是在22:40 [10:40 pm]发出此通知.顺便说一句,这个警报应该每天同时重复.

public void show_notification() {
        CharSequence notify_msg="Don't foget!";
        CharSequence title= "you ve been notified by My app";
        CharSequence details= "It works!";
        NotificationManager nm= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notify= new Notification(android.R.drawable.stat_notify_more,
                                notify_msg, 
                                System.currentTimeMillis());
        Context mycontext= ActA.this;
        Intent myintent= new Intent (mycontext, ActA.class);
        PendingIntent pending= PendingIntent.getActivity(mycontext, 0, myintent, 0); ///0's are not applicable here
        notify.setLatestEventInfo(mycontext, title, details, pending);

        nm.notify(0, notify);



    }
Run Code Online (Sandbox Code Playgroud)

我希望你能详细回答,因为我是一个非常新的开发者.

Mur*_*bul 8

这很简单.你可以使用报警管理器.您可能需要修改清单文件并注册应用程序以从alarmmanager获取通知.现在,您可以要求警报管理器类在您的应用程序将收到的所需时间发送消息.

您必须以响应此消息的方式对活动进行编程,并向用户显示通知.

  • http://android-er.blogspot.in/2010/10/simple-example-of-alarm-service-using.html - 你可以用通知替换吐司 (4认同)