千家信息网

如何用HTML+JS实现Android闹钟功能

发表于:2024-10-26 作者:千家信息网编辑
千家信息网最后更新 2024年10月26日,本篇文章给大家分享的是有关如何用HTML+JS实现Android闹钟功能,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。参数:argu:型
千家信息网最后更新 2024年10月26日如何用HTML+JS实现Android闹钟功能

本篇文章给大家分享的是有关如何用HTML+JS实现Android闹钟功能,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

参数:

argu:型如"key1=value1;key2=value2;......"的参数表。首先,该参数表支持rexseeNotification.show()函数的所有参数,用于显示通知(调用rexseeNotification.show()),请参见rexseeNotification。另外,该参数表增加了以下参数:

forcerepeat:true或false。当该闹钟是由推送信息而非页面设定时,如果id和之前的推送信息的id重复,由该参数决定是否强制重新执行,默认为false,即不会重复执行任何id重复的推送信息。

command:闹钟响时要执行的命令,目前支持的命令包括:

notification:发送通知,默认值。

startApplication:启动程序。

cleanApplicationData:清楚本程序的业务数据(私有内存中的所有数据)。

notificationimmediately:true或false,无论命令是否notification,该参数都允许系统在设置闹钟的***时间先发送一个通知,然后在指定的时间延迟后再执行命令,默认为false。

notificationafterexec:true或false,无论命令是否notification,该参数都允许系统在执行完命令后发送一个通知,默认为false。

alermname:闹钟的名称,默认为"defaultAlerm"。

alermfirsttime:时间戳,***次闹钟响(即执行命令)的时间,如果设为0或其他小于当前时间的时间戳,命令将立即执行,默认为立即执行。

alermrepeatinterval:毫秒数,***次闹钟响之后,间隔该时间后重复执行命令,如果小于零,将不会重复执行。

startApplicationUrl:如果命令为startApplication,程序启动后访问的URL地址。

示例:

exseeAlarm.set('command=startApplication;startApplicationUrl=http://www.rexsee.com/rexsee/alarmClock.html;alermName=test;alermfirsttime='+(rexseeAlarm.getCurrentTime()+5000)+';title=闹钟测试;message=闹钟测试内容;url=http://www.rexsee.com/rexsee/alarmClock.html');  rexseeDialog.toast('设置完毕!');

Rexsee的Android Alarm源码如下:

/*  * Copyright (C) 2011 The Rexsee Open Source Project  *  * Licensed under the Rexsee License, Version 1.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *  *      http://www.rexsee.com/CN/legal/license.html  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  */   package rexsee.core.alarm;    import rexsee.core.browser.JavascriptInterface;   import rexsee.core.browser.RexseeBrowser;   import rexsee.core.device.NotificationArgumentsSheet;   import rexsee.core.device.RexseeNotification;   import rexsee.core.receiver._Receiver;   import android.app.AlarmManager;   import android.app.PendingIntent;   import android.content.Context;   import android.content.Intent;   import android.database.Cursor;   import android.database.sqlite.SQLiteDatabase;    public class RexseeAlarm implements JavascriptInterface {           private static final String INTERFACE_NAME = "Alarm";          @Override          public String getInterfaceName() {                  return mBrowser.application.resources.prefix + INTERFACE_NAME;          }          @Override          public JavascriptInterface getInheritInterface(RexseeBrowser childBrowser) {                  return this;          }          @Override          public JavascriptInterface getNewInterface(RexseeBrowser childBrowser) {                  return new RexseeAlarm(childBrowser);          }           public static final String ALARM_ACTION = "action.alarm.id_";          public static final String ALARM_EXTRA_ARGU = "argu";           public static final String DATABASE_ALARM = "alarm.db";          public static final String TABLE_ALARM = "alarm";           private final Context mContext;          private final RexseeBrowser mBrowser;           public RexseeAlarm(RexseeBrowser browser) {                  mBrowser = browser;                  mContext = browser.getContext();          }          public RexseeAlarm(Context context) {                  mBrowser = null;                  mContext = context;          }           private static void _setAlarm(Context context, AlarmManager mgr, String body, boolean save) {                  NotificationArgumentsSheet argu = (new NotificationArgumentsSheet()).parseArguments(body);                  if (argu.notificationimmediately) {                          (new RexseeNotification(context)).show(argu);                  }                  if (argu.getAlermFirstTime() > System.currentTimeMillis()) {                          Intent intent = new Intent(context, _Receiver.class);                          intent.setAction(ALARM_ACTION + argu.alermname);                          intent.putExtra(ALARM_EXTRA_ARGU, body);                          PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);                          mgr.cancel(pendingIntent);                          long interval = argu.getAlermRepeatInterval();                          if (interval > 0) {                                  mgr.setRepeating(AlarmManager.RTC_WAKEUP, argu.getAlermFirstTime(), interval, pendingIntent);                          } else {                                  mgr.set(AlarmManager.RTC_WAKEUP, argu.getAlermFirstTime(), pendingIntent);                          }                          if (save) {                                  SQLiteDatabase db = context.openOrCreateDatabase(DATABASE_ALARM, Context.MODE_PRIVATE, null);                                  try {                                          db.execSQL("CREATE TABLE if not exists " + TABLE_ALARM + " (name TEXT, argu TEXT, Primary key(name));");                                          db.execSQL("DELETE FROM " + TABLE_ALARM + " WHERE name='" + argu.alermname + "';");                                          db.execSQL("INSERT INTO " + TABLE_ALARM + " VALUES ('" + argu.alermname + "', '" + body + "');");                                  } catch (Exception e) {                                  }                                  db.close();                          }                  } else {                          exec(context, body);                  }          }          private static void _deleteAlarm(Context context, String name) {                  SQLiteDatabase db = context.openOrCreateDatabase(DATABASE_ALARM, Context.MODE_PRIVATE, null);                  try {                          db.execSQL("DELETE FROM " + TABLE_ALARM + " WHERE name='" + name + "';");                  } catch (Exception e) {                  }                  db.close();          }           public static void exec(Context context, String body) {                  NotificationArgumentsSheet argu = (new NotificationArgumentsSheet()).parseArguments(body);                  if (argu.getAlermRepeatInterval() <= 0) {                          _deleteAlarm(context, argu.alermname);                  }                  (new RexseeRemoteCommand(context, body)).exec();          }          public static void updateAlarm(Context context) {                  SQLiteDatabase db = context.openOrCreateDatabase(DATABASE_ALARM, Context.MODE_PRIVATE, null);                  AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);                  try {                          db.execSQL("CREATE TABLE if not exists " + TABLE_ALARM + " (name TEXT, argu TEXT, Primary key(name));");                          Cursor cursor = db.rawQuery("SELECT * from " + TABLE_ALARM + ";", null);                          if (cursor != null && cursor.getCount() != 0) {                                  for (int i = 0; i < cursor.getCount(); i++) {                                          cursor.moveToPosition(i);                                          _setAlarm(context, mgr, cursor.getString(1), false);                                  }                          }                          cursor.close();                  } catch (Exception e) {                  }                  db.close();          }           //JavaScript Interface          public void set(String body) {                  _setAlarm(mContext, (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE), body, true);          }          public String get() {                  SQLiteDatabase db = mContext.openOrCreateDatabase(DATABASE_ALARM, Context.MODE_PRIVATE, null);                  String rtn = "";                  try {                          Cursor cursor = db.rawQuery("SELECT * from " + TABLE_ALARM + ";", null);                          if (cursor != null && cursor.getCount() != 0) {                                  for (int i = 0; i < cursor.getCount(); i++) {                                          cursor.moveToPosition(i);                                          if (i > 0) rtn += ",";                                          rtn += "{";                                          rtn += "\"name\":\"" + cursor.getString(0) + "\"";                                          rtn += ",\"argu\":\"" + cursor.getString(1) + "\"";                                          rtn += "}";                                  }                          }                          cursor.close();                  } catch (Exception e) {                          if (mBrowser != null) mBrowser.exception(getInterfaceName(), e);                  }                  db.close();                  return "[" + rtn + "]";          }          public void cancel(String name) {                  Intent intent = new Intent(mContext, _Receiver.class);                  intent.setAction(ALARM_ACTION + name);                  PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);                  AlarmManager mgr = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);                  mgr.cancel(pendingIntent);                  _deleteAlarm(mContext, name);          }           public long getCurrentTime() {                  return System.currentTimeMillis();          }          public long getMillisPerHour() {                  return 3600 * 1000;          }          public long getMillisPerDay() {                  return 3600 * 1000 * 24;          }    }

以上就是如何用HTML+JS实现Android闹钟功能,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。

闹钟 命令 参数 时间 信息 参数表 程序 推送 功能 数据 更多 知识 篇文章 系统 支持 测试 实用 清楚 业务 内存 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 网络技术2021大纲 亲爱的热爱的网络安全竞赛片段 广州万物互联网科技有限 网吧还原软件开发 剑三指尖江湖服务器掉线 服务器会一直保存我们的信息吗 腾讯模拟器如何清理数据库 互联网科技公司年报 控制器软件开发测试台架厂家 网络技术发展及现状 服务器nvme硬盘是什么接口 江苏数据网络技术服务询问报价 后台服务器出现安全问题 mmm服务器在哪 以人为中心的设计与软件开发 网络安全扫描软件挣钱 东城区现代软件开发经历 崇明区智能软件开发调试 2021 网络安全宣传视频 方舟服务器画质为什么这么模糊 女孩学网络技术专业 新建数据库表字段怎么填 数据库模式为 大学生网络安全教育的历史 服务器电源定制公司 药监赋码系统数据库怎么删除 命运2怎么连接不了服务器 学软件开发的买什么电脑 苹果手机连接服务器出现问题 农业一张图数据库
0