• 第二阶段冲刺第二天


    今天主要是将在昨天留下的遗留问题解决掉了,然后开始写提醒的功能,但是将代码放上去之后并没有实现这样的功能。

    public class MainActivity extends Activity {
    
     
    
        @Override
    
        protected void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_main);
    
     
    
            Intent intent = new Intent(this, AutoReceiver.class);
    
            intent.setAction("VIDEO_TIMER");
    
                    // PendingIntent这个类用于处理即将发生的事情               
    
                    PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0);
    
            AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    
                    // AlarmManager.ELAPSED_REALTIME_WAKEUP表示闹钟在睡眠状态下会唤醒系统并执行提示功能,该状态下闹钟使用相对时间
    
                    // SystemClock.elapsedRealtime()表示手机开始到现在经过的时间
    
                    am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
    
                    SystemClock.elapsedRealtime(), 10 * 1000, sender);
    
        }
    
    }
    public class AutoReceiver extends BroadcastReceiver {
    
        private static final int NOTIFICATION_FLAG = 1;
    
     
    
        @SuppressLint("NewApi")
    
        @Override
    
        public void onReceive(Context context, Intent intent) {
    
            if (intent.getAction().equals("VIDEO_TIMER")) {            
    
                PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
    
                        new Intent(context, MainActivity.class), 0);
    
                // 通过Notification.Builder来创建通知,注意API Level
    
                // API16之后才支持
    
                Notification notify = new Notification.Builder(context)
    
                        .setSmallIcon(R.drawable.ic_launcher)
    
                        .setTicker("TickerText:" + "您有新短消息,请注意查收!")
    
                        .setContentTitle("Notification Title")
    
                        .setContentText("This is the notification message")
    
                        .setContentIntent(pendingIntent).setNumber(1).build(); // 需要注意build()是在API
    
                                                       // level16及之后增加的,API11可以使用getNotificatin()来替代
    
                notify.flags |= Notification.FLAG_AUTO_CANCEL; // FLAG_AUTO_CANCEL表明当通知被用户点击时,通知将被清除。
    
                // 在Android进行通知处理,首先需要重系统哪里获得通知管理器NotificationManager,它是一个系统Service。
    
                NotificationManager manager = (NotificationManager) context
    
                        .getSystemService(Context.NOTIFICATION_SERVICE);
    
                manager.notify(NOTIFICATION_FLAG, notify);// 步骤4:通过通知管理器来发起通知。如果id不同,则每click,在status哪里增加一个提示
    
            }
    
        }
    
     
    
    }
  • 相关阅读:
    robotframework eclipse Robot Reference libraries不显示(selenium library无法导入)问题解决办法
    Navicat_Keygen_Patch 5.6如何使用
    电子标签拣货系统DPS
    matplotlib中的bar图
    Windows 10 清除文件
    npm包的上传npm包的步骤,与更新和下载步骤
    深入理解JWT的使用场景和优劣
    关于Vue.js去掉#号路由
    关于sklearn中的导包交叉验证问题
    python函数作用域
  • 原文地址:https://www.cnblogs.com/zuoshenmedoudui/p/12963402.html
Copyright © 2020-2023  润新知