3

show_notification()ユーザーがボタンを押したときに呼び出す関数があります。ポイントは、[以下の関数のように] クリックしたら通知を表示する代わりに、特定のtime= hours:mins
時間と分でこの通知を表示したいということです [たとえば、時間 = 22 と時間 = 22 とminutes=40..つまり、この通知を 22:40 [午後 10:40] に起動します]。ちなみに、このアラームは毎日同じ時刻に繰り返す必要があります。

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);



    }

私は非常に新しい開発者であるため、詳細に回答していただければ幸いです。

4

1 に答える 1

8

それは非常に簡単です。アラームマネージャを使用できます。マニフェスト ファイルを変更し、alarmmanager から通知を受け取るためにアプリケーションを登録する必要がある場合があります。これで、アプリケーションが受信する希望の時間にメッセージを送信するようにアラーム マネージャ クラスに依頼できます。

このメッセージに応答してユーザーに通知を表示するように、アクティビティをプログラムする必要があります。

于 2012-12-16T01:50:05.057 に答える