日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 闹钟,实现demo

發布時間:2023/12/10 Android 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 闹钟,实现demo 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

可變時間格式:"yyyy-MM-dd HH:mm:ss"

保存鬧鐘時間:

  • SimpleDateFormat df = new SimpleDateFormat("HH:mm");//設置日期格式

  • String thistime = df.format(new Date());

  • SharedPreferences sharedPreferences = getSharedPreferences("industryInfo", Context.MODE_PRIVATE); //私有數據

  • SharedPreferences.Editor editor = sharedPreferences.edit();//獲取編輯器

  • editor.putString(“retime”, thistime);//名稱 id

  • editor.commit();//提交

?

監聽時間變化:

監聽service

/*** 作者:created by meixi* 郵箱:13164716840@163.com* 日期:2018/9/27 09*/ public class Serview extends Service {/*** 廣播接受者*/private BroadcastReceiver mBatInfoReceiver;private String TAG = "lgq--------------------";@Overridepublic void onCreate() {super.onCreate();initBroadcastReceiver();}/*** 注冊廣播*/private void initBroadcastReceiver() {final IntentFilter filter = new IntentFilter();// 屏幕滅屏廣播filter.addAction(Intent.ACTION_SCREEN_OFF);//關機廣播filter.addAction(Intent.ACTION_SHUTDOWN);// 屏幕亮屏廣播filter.addAction(Intent.ACTION_SCREEN_ON);// 屏幕解鎖廣播 // filter.addAction(Intent.ACTION_USER_PRESENT);// 當長按電源鍵彈出“關機”對話或者鎖屏時系統會發出這個廣播// example:有時候會用到系統對話框,權限可能很高,會覆蓋在鎖屏界面或者“關機”對話框之上,// 所以監聽這個廣播,當收到時就隱藏自己的對話,如點擊pad右下角部分彈出的對話框filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);//監聽日期變化filter.addAction(Intent.ACTION_DATE_CHANGED);filter.addAction(Intent.ACTION_TIME_CHANGED);filter.addAction(Intent.ACTION_TIME_TICK);mBatInfoReceiver = new BroadcastReceiver() {@Overridepublic void onReceive(final Context context, final Intent intent) {String action = intent.getAction();if (Intent.ACTION_SCREEN_ON.equals(action)) {Log.i(TAG, "screen on");} else if (Intent.ACTION_TIME_TICK.equals(action)) {//日期變化步數重置為0Log.i("lgq0000000000000000","日期變化步數重置為0===="+action);SharedPreferences share = getSharedPreferences("industryInfo", Activity.MODE_PRIVATE);String industryOne = share.getString("retime", "");//名稱 獲取idif (industryOne.equals(new SimpleDateFormat("HH:mm").format(new Date()))){//todo 鬧鐘到了}}}};registerReceiver(mBatInfoReceiver, filter);}@Nullable@Overridepublic IBinder onBind(Intent intent) {return null;} } <service android:name=".testt.Serview"><intent-filter><!-- 系統啟動完成后會調用--><action android:name="android.intent.action.BOOT_COMPLETED" /><action android:name="android.intent.action.DATE_CHANGED" /><action android:name="android.intent.action.MEDIA_MOUNTED" /><action android:name="android.intent.action.USER_PRESENT" /><action android:name="android.intent.action.ACTION_TIME_TICK" /><action android:name="android.intent.action.ACTION_POWER_CONNECTED" /><action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" /></intent-filter> </service>

?

/*** 開啟計步服務*/private void setupService() {Intent intent = new Intent(this, Serview.class); // isBind = bindService(intent, conn, Context.BIND_AUTO_CREATE);startService(intent);}

?

?

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的Android 闹钟,实现demo的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。