方法设置锁屏状态下点亮屏幕,并弹出闹钟提示信息,

首先声明,我是一个菜鸟。一下文章中出现技术误导情况盖不负责

    锁屏状态下点亮幕屏,并弹出闹钟提示信息,可以在锁屏界面上取消闹钟;应用广播接收闹钟准时:

    

    

    

    面下是例子里的核心码代如下

    

    

    

    android 设置准时闹钟(包含醒提一次和环循醒提):

    

    Intent intent = new Intent(MainActivity.this,MyAlarmBroadCast.class);  

    

            /**

    

             * context 指定实例

    

             * requestcode 可以作为闹钟的唯一性标识

    

             * intent The Intent to be broadcast

    

             * flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT,

    

             */

    

            PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);  

    

              

    

            /*** 

    

             * 获得全局准时器的务服管理器 

    

             */  

    

            AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);  

    

          

    

            /** 

    

             * 指定的任务只会执行一次,如果该pendingIntent指定的任务已被执行过了,那么该方法直接会被cancel掉。 

    

             *  set(int type, long triggerAtTime, PendingIntent operation) 

    

             *  type 指定准时模式。 

    

             *  triggerAtTime 触发任务的间时。该数参和准时模式非亲非故 

    

             *  operation 该数参指定一个广播Intent,当间时到了时,系统会广播里头的intent,触发响应的广播接收者执行某些作操,比如响铃…… 

    

             */  

    

            alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);  

    

                /** 

    

                 * 通过该方法指定的任务会始终距离执行,第三个数参就指定了执行的间时距离 

    

                 * 如果我们想取消的话,请应用:alarmManager.cancel(pendingIntent); 

    

                 * 意注,这里的pendingIntent要和setRepeating方法中的致一哦。 

    

                 */  

    

            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 5*1000, pendingIntent);  

    

    

    android取消指定闹钟:

    

    Intent intent = new Intent(AlarmReminderActivity.this,MyAlarmBroadCast.class);  

    

    /**

    

             * context 指定实例

    

             * requestcode 可以作为闹钟的唯一性标识,根据这个的不同来除删闹钟

    

    每日一道理
试试看——不是像企鹅那样静静的站在海边,翘首企盼机会的来临,而是如苍鹰一般不停的翻飞盘旋,执著的寻求。 试试看——不是面对峰回路转、杂草丛生的前途枉自嗟叹,而是披荆斩棘,举步探索。 试试看——不是拘泥于命运的禁锢,听凭命运的摆布,而是奋力敲击其神秘的门扉,使之洞开一个新的天地。微笑着,去唱生活的歌谣。

             * intent The Intent to be broadcast

    

             * flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT,

    

             */

    

            PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);  

    

              

    

            /*** 

    

             * 获得全局准时器的务服管理器 

    

             */  

    

            AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);  

    

            

    

            alarmManager.cancel(pendingIntent);

    

    

    android醒唤锁定幕屏:

    

    PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);

    

    WakeLock mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.SCREEN_DIM_WAKE_LOCK, "SimpleTimer");

    

            mWakelock.acquire();

    

    

    该方法的应用一定要随伴mWakelock.release();否则会报异常;

    

    荐推应用方法:在醒唤幕屏示显的activity的onResume方法中醒唤,在onPause方法中release;

    

    

    

    如何让activity示显在锁屏界面上:

    

    首先要醒唤锁定幕屏,然后设置activity的属性,使它可以示显在锁屏界面上;

    

    醒唤幕屏的方法参考面上;

    

    activity的设置包含两部分:

    

    1-onCreate方法中设置如下码代:

    

    super.onCreate(savedInstanceState);

    

    final Window win = getWindow();

    

     win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED

    

     | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

    

     win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

    

     | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    

    setContentView(R.layout.act_alarmreminder);

    

    2-AndroidManifest.xml对该activity的声明中设置属性:

    

    android:label="@string/app_name" 

    

                android:launchMode="singleInstance"

    

    android:excludeFromRecents="true"

    

    android:taskAffinity=""

    

    android:theme="@android:style/Theme.Wallpaper.NoTitleBar"(这一行很要重)

    

    android:configChanges="orientation|keyboardHidden|keyboard|navigation"

文章结束给大家分享下程序员的一些笑话语录: 关于编程语言
如果 C++是一把锤子的话,那么编程就会变成大手指头。
如果你找了一百万只猴子来敲打一百万个键盘,那么会有一只猴子会敲出一 段 Java 程序,而其余的只会敲出 Perl 程序。
一阵急促的敲门声,“谁啊!”,过了 5 分钟,门外传来“Java”。
如果说 Java 很不错是因为它可以运行在所有的操作系统上,那么就可以说 肛交很不错,因为其可以使用于所有的性别上。

posted @ 2013-04-28 20:04  xinyuyuanm  阅读(1298)  评论(0编辑  收藏  举报