日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
用HTML+JS實(shí)現(xiàn)Android鬧鐘功能附Alarm代碼分享

參數(shù):

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名與空間、虛擬空間、營銷軟件、網(wǎng)站建設(shè)、平陽網(wǎng)站維護(hù)、網(wǎng)站推廣。

argu:型如“key1=value1;key2=value2;......”的參數(shù)表。首先,該參數(shù)表支持rexseeNotification.show()函數(shù)的所有參數(shù),用于顯示通知(調(diào)用rexseeNotification.show()),請參見rexseeNotification。另外,該參數(shù)表增加了以下參數(shù):

forcerepeat:true或false。當(dāng)該鬧鐘是由推送信息而非頁面設(shè)定時,如果id和之前的推送信息的id重復(fù),由該參數(shù)決定是否強(qiáng)制重新執(zhí)行,默認(rèn)為false,即不會重復(fù)執(zhí)行任何id重復(fù)的推送信息。

command:鬧鐘響時要執(zhí)行的命令,目前支持的命令包括:

notification:發(fā)送通知,默認(rèn)值。

startApplication:啟動程序。

cleanApplicationData:清楚本程序的業(yè)務(wù)數(shù)據(jù)(私有內(nèi)存中的所有數(shù)據(jù))。

notificationimmediately:true或false,無論命令是否notification,該參數(shù)都允許系統(tǒng)在設(shè)置鬧鐘的***時間先發(fā)送一個通知,然后在指定的時間延遲后再執(zhí)行命令,默認(rèn)為false。

notificationafterexec:true或false,無論命令是否notification,該參數(shù)都允許系統(tǒng)在執(zhí)行完命令后發(fā)送一個通知,默認(rèn)為false。

alermname:鬧鐘的名稱,默認(rèn)為"defaultAlerm"。

alermfirsttime:時間戳,***次鬧鐘響(即執(zhí)行命令)的時間,如果設(shè)為0或其他小于當(dāng)前時間的時間戳,命令將立即執(zhí)行,默認(rèn)為立即執(zhí)行。

alermrepeatinterval:毫秒數(shù),***次鬧鐘響之后,間隔該時間后重復(fù)執(zhí)行命令,如果小于零,將不會重復(fù)執(zhí)行。

startApplicationUrl:如果命令為startApplication,程序啟動后訪問的URL地址。

示例:

 
 
  1. exseealarm.set('command=startApplication;startApplicationUrl=http://www.rexsee.com/rexsee/alarmClock.html;alermName=test;alermfirsttime='+(rexseeAlarm.getCurrentTime()+5000)+';title=鬧鐘測試;message=鬧鐘測試內(nèi)容;url=http://www.rexsee.com/rexsee/alarmClock.html');  
  2. rexseeDialog.toast('設(shè)置完畢!');  

Rexsee的Android Alarm源碼如下:

 
 
  1. /*  
  2. * Copyright (C) 2011 The Rexsee Open Source Project  
  3. *  
  4. * Licensed under the Rexsee License, Version 1.0 (the "License");  
  5. * you may not use this file except in compliance with the License.  
  6. * You may obtain a copy of the License at  
  7. *  
  8. *      http://www.rexsee.com/CN/legal/license.html  
  9. *  
  10. * Unless required by applicable law or agreed to in writing, software  
  11. * distributed under the License is distributed on an "AS IS" BASIS,  
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  13. * See the License for the specific language governing permissions and  
  14. * limitations under the License.  
  15. */  
  16.  
  17. package rexsee.core.alarm;   
  18.  
  19. import rexsee.core.browser.JavascriptInterface;   
  20. import rexsee.core.browser.RexseeBrowser;   
  21. import rexsee.core.device.NotificationArgumentsSheet;   
  22. import rexsee.core.device.RexseeNotification;   
  23. import rexsee.core.receiver._Receiver;   
  24. import android.app.AlarmManager;   
  25. import android.app.PendingIntent;   
  26. import android.content.Context;   
  27. import android.content.Intent;   
  28. import android.database.Cursor;   
  29. import android.database.sqlite.SQLiteDatabase;   
  30.  
  31. public class RexseeAlarm implements JavascriptInterface {   
  32.  
  33.        private static final String INTERFACE_NAME = "Alarm";   
  34.        @Override   
  35.        public String getInterfaceName() {   
  36.                return mBrowser.application.resources.prefix + INTERFACE_NAME;   
  37.        }   
  38.        @Override   
  39.        public JavascriptInterface getInheritInterface(RexseeBrowser childBrowser) {   
  40.                return this;   
  41.        }   
  42.        @Override   
  43.        public JavascriptInterface getNewInterface(RexseeBrowser childBrowser) {   
  44.                return new RexseeAlarm(childBrowser);   
  45.        }   
  46.  
  47.        public static final String ALARM_ACTION = "action.alarm.id_";   
  48.        public static final String ALARM_EXTRA_ARGU = "argu";   
  49.  
  50.        public static final String DATABASE_ALARM = "alarm.db";   
  51.        public static final String TABLE_ALARM = "alarm";   
  52.  
  53.        private final Context mContext;   
  54.        private final RexseeBrowser mBrowser;   
  55.  
  56.        public RexseeAlarm(RexseeBrowser browser) {   
  57.                mBrowser = browser;   
  58.                mContext = browser.getContext();   
  59.        }   
  60.        public RexseeAlarm(Context context) {   
  61.                mBrowser = null;   
  62.                mContext = context;   
  63.        }   
  64.  
  65.        private static void _setAlarm(Context context, AlarmManager mgr, String body, boolean save) {   
  66.                NotificationArgumentsSheet argu = (new NotificationArgumentsSheet()).parseArguments(body);   
  67.                if (argu.notificationimmediately) {   
  68.                        (new RexseeNotification(context)).show(argu);   
  69.                }   
  70.                if (argu.getAlermFirstTime() > System.currentTimeMillis()) {   
  71.                        Intent intent = new Intent(context, _Receiver.class);   
  72.                        intent.setAction(ALARM_ACTION + argu.alermname);   
  73.                        intent.putExtra(ALARM_EXTRA_ARGU, body);   
  74.                        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);   
  75.                        mgr.cancel(pendingIntent);   
  76.                        long interval = argu.getAlermRepeatInterval();   
  77.                        if (interval > 0) {   
  78.                                mgr.setRepeating(AlarmManager.RTC_WAKEUP, argu.getAlermFirstTime(), interval, pendingIntent);   
  79.                        } else {   
  80.                                mgr.set(AlarmManager.RTC_WAKEUP, argu.getAlermFirstTime(), pendingIntent);   
  81.                        }   
  82.                        if (save) {   
  83.                                SQLiteDatabase db = context.openOrCreateDatabase(DATABASE_ALARM, Context.MODE_PRIVATE, null);   
  84.                                try {   
  85.                                        db.execSQL("CREATE TABLE if not exists " + TABLE_ALARM + " (name TEXT, argu TEXT, Primary key(name));");   
  86.                                        db.execSQL("DELETE FROM " + TABLE_ALARM + " WHERE name='" + argu.alermname + "';");   
  87.                                        db.execSQL("INSERT INTO " + TABLE_ALARM + " VALUES ('" + argu.alermname + "', '" + body + "');");   
  88.                                } catch (Exception e) {   
  89.                                }   
  90.                                db.close();   
  91.                        }   
  92.                } else {   
  93.                        exec(context, body);   
  94.                }   
  95.        }   
  96.        private static void _deleteAlarm(Context context, String name) {   
  97.                SQLiteDatabase db = context.openOrCreateDatabase(DATABASE_ALARM, Context.MODE_PRIVATE, null);   
  98.                try {   
  99.                        db.execSQL("DELETE FROM " + TABLE_ALARM + " WHERE name='" + name + "';");   
  100.                } catch (Exception e) {   
  101.                }   
  102.                db.close();   
  103.        }   
  104.  
  105.        public static void exec(Context context, String body) {   
  106.                NotificationArgumentsSheet argu = (new NotificationArgumentsSheet()).parseArguments(body);   
  107.                if (argu.getAlermRepeatInterval() <= 0) {   
  108.                        _deleteAlarm(context, argu.alermname);   
  109.                }   
  110.                (new RexseeRemoteCommand(context, body)).exec();   
  111.        }   
  112.        public static void updateAlarm(Context context) {   
  113.                SQLiteDatabase db = context.openOrCreateDatabase(DATABASE_ALARM, Context.MODE_PRIVATE, null);   
  114.                AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);   
  115.                try {   
  116.                        db.execSQL("CREATE TABLE if not exists " + TABLE_ALARM + " (name TEXT, argu TEXT, Primary key(name));");   
  117.                        Cursor cursor = db.rawQuery("SELECT * from " + TABLE_ALARM + ";", null);   
  118.                        if (cursor != null && cursor.getCount() != 0) {   
  119.                                for (int i = 0; i < cursor.getCount(); i++) {   
  120.                                        cursor.moveToPosition(i);   
  121.                                        _setAlarm(context, mgr, cursor.getString(1), false);   
  122.                                }   
  123.                        }   
  124.                        cursor.close();   
  125.                } catch (Exception e) {   
  126.                }   
  127.                db.close();   
  128.        }   
  129.  
  130.        //JavaScript Interface   
  131.        public void set(String body) {   
  132.                _setAlarm(mContext, (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE), body, true);   
  133.        }   
  134.        public String get() {   
  135.                SQLiteDatabase db = mContext.openOrCreateDatabase(DATABASE_ALARM, Context.MODE_PRIVATE, null);   
  136.                String rtn = "";   
  137.                try {   
  138.                        Cursor cursor = db.rawQuery("SELECT * from " + TABLE_ALARM + ";", null);   
  139.                        if (cursor != null && cursor.getCount() != 0) {   
  140.                                for (int i = 0; i < cursor.getCount(); i++) {   
  141.                                        cursor.moveToPosition(i);   
  142.                                        if (i > 0) rtn += ",";   
  143.                                        rtn += "{";   
  144.                                        rtn += "\"name\":\"" + cursor.getString(0) + "\"";   
  145.                                        rtn += ",\"argu\":\"" + cursor.getString(1) + "\"";   
  146.                                        rtn += "}";   
  147.                                }   
  148.                        }   
  149.                        cursor.close();   
  150.                } catch (Exception e) {   
  151.                        if (mBrowser != null) mBrowser.exception(getInterfaceName(), e);   
  152.                }   
  153.                db.close();   
  154.                return "[" + rtn + "]";   
  155.        }   
  156.        public void cancel(String name) {   
  157.                Intent intent = new Intent(mContext, _Receiver.class);   
  158.                intent.setAction(ALARM_ACTION + name);   
  159.                PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);   
  160.                AlarmManager mgr = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);   
  161.                mgr.cancel(pendingIntent);   
  162.                _deleteAlarm(mContext, name);   
  163.        }   
  164.  
  165.        public long getCurrentTime() {   
  166.                return System.currentTimeMillis();   
  167.        }   
  168.        public long getMillisPerHour() {   
  169.                return 3600 * 1000;   
  170.        }   
  171.        public long getMillisPerDay() {   
  172.                return 3600 * 1000 * 24;   
  173.        }   
  174.  
  175. }  

 


當(dāng)前名稱:用HTML+JS實(shí)現(xiàn)Android鬧鐘功能附Alarm代碼分享
路徑分享:http://www.dlmjj.cn/article/cdiocph.html