• 第二阶段冲刺第四天


    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哪里增加一个提示
    
            }
    
        }
    
     
    
    }
        <uses-sdk
    
            android:minSdkVersion="8"
    
            android:targetSdkVersion="19" />
    
    <receiver            android:name=".AutoReceiver"            android:label="@string/app_name" >        
        <intent-filter>          
          <action android:name="android.intent.action.BOOT_COMPLETED" />                 <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>    
        </receiver>

    这是可以代码但是出现了小问题,不能发送消息还需要改进;

  • 相关阅读:
    利用KINECT+OPENCV检测手势的演示程序
    关于PPC软件的开发库
    FlashGet的IE加载项与IE8不兼容
    ubuntu9.04 安装字体 后记
    【pys60笔记】中文
    【pys60学习笔记】S60 模拟器使用。
    ubuntu9.04 安装字体
    IDE硬盘安装Windows 7 7106(光驱与硬盘共用一个IDE)
    易歌——web在线听歌桌面程序。带全局键控制。
    MapX直连Oracle——MapX5配合Oracle时,对中文表名支持不好
  • 原文地址:https://www.cnblogs.com/1234yyf/p/12976579.html
Copyright © 2020-2023  润新知