189 8069 5689

Android实现闹钟功能小Dome-创新互联

闹钟闹不醒的可以自己去调整下,这个最是最基本的

站在用户的角度思考问题,与客户深入沟通,找到遂川网站设计与遂川网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站设计、做网站、企业官网、英文网站、手机端网站、网站推广、域名申请虚拟主机、企业邮箱。业务覆盖遂川地区。

MainActivity

public class MainActivity extends AppCompatActivity {

  private AlarmManager alarmManager;
  private PendingIntent pendingIntent;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //获取闹钟管理者
    alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);


  }

  public void setAlarmOne(View view) {
    //获取当前系统时间
    Calendar calendar = Calendar.getInstance();
    int huor = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);


    //1 弹出时间对话框
    TimePickerDialog timePickerDialog = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {

      @Override
      public void onTimeSet(TimePicker view, int i, int i1) {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, i);
        c.set(Calendar.MINUTE, i1);
        //2确定好选择的时间
        //3设置闹钟
        //4当时间一到,将执行的响应
        Intent intent=new Intent();
        intent.setAction("com.zking.risk_android_alarn_notification.RING");
        pendingIntent = PendingIntent.getBroadcast(MainActivity.this,0x101,intent,0);
        alarmManager.set(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(), pendingIntent);
      }
    }, huor, minute, true);
    timePickerDialog.show();
  }

  public void setAlarmCycle(View view) {
    //获取当前系统时间
    Calendar calendar=Calendar.getInstance();
    int hour=calendar.get(Calendar.HOUR_OF_DAY);
    int minute=calendar.get(Calendar.MINUTE);

    //01.弹出时间对话框
    TimePickerDialog timePickerDialog=new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
      @Override
      public void onTimeSet(TimePicker timePicker, int i, int i1) {
        Calendar c=Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY,i);
        c.set(Calendar.MINUTE,i1);
        //02.确定好选择的时间
        //03.设置闹钟

        //04.当之间一到,将执行的响应
        Intent intent=new Intent();
        intent.setAction("com.zking.risk_android_alarn_notification.RING");
        pendingIntent = PendingIntent.getBroadcast(MainActivity.this,0x102,intent,0);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(),5000, pendingIntent);
      }
    },hour,minute,true);
    timePickerDialog.show();

  }

  public void cancelAlarmCycle(View view){
    alarmManager.cancel(pendingIntent);
  }


}


新闻名称:Android实现闹钟功能小Dome-创新互联
链接地址:http://cdxtjz.com/article/gpdsg.html

其他资讯