【问题标题】:How to set Notification on time如何按时设置通知
【发布时间】:2013-02-25 19:19:04
【问题描述】:

大家好,我创建了课程,现在我想按时设置Notification。 例如,如果有人单击按钮,则应在十分钟后显示 Notification

代码

TextView txtV;
Button bnot;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.receiving);
    txtV=(TextView)findViewById(R.id.txtV);
    bnot=(Button)findViewById(R.id.bN);
    bnot.setOnClickListener(this);
    Bundle extras = getIntent().getExtras();
    if(extras !=null) {
        String value = extras.getString("key"); //assign it.
        txtV.setText("Remember :"+value); //set it to textview.
      }
    }


@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    Intent intent = new Intent();
      Bundle extras = getIntent().getExtras();
     String value = extras.getString("key"); //assign it.
     PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
    Notification noti = new Notification.Builder(this)
    .setTicker("Remember")
    .setContentTitle(value)
    .setContentText("Notification content.")
    .setSmallIcon(R.drawable.ic_launcher)
    .setContentIntent(pIntent).getNotification();
    noti.flags=Notification.FLAG_AUTO_CANCEL;
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(0, noti); 

}

}

【问题讨论】:

    标签: android time timer push-notification settimeout


    【解决方案1】:

    在按钮被点击后的 10 分钟内发出警报

    【讨论】:

      【解决方案2】:
      AlarmManager alarm = (AlarmManager)getActivity().getSystemService(Context.ALARM_SERVICE);
      Calendar cal = Calendar.getInstance();
      //1000*60*10 = 10 minutes
      alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 1000*60*10, pendingIntent);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-20
        • 1970-01-01
        • 1970-01-01
        • 2023-03-10
        • 1970-01-01
        • 2019-01-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多